Skip to content

Instantly share code, notes, and snippets.

@andrii-marushchak
Created January 14, 2025 22:46
Show Gist options
  • Save andrii-marushchak/8b57fd72bf1ea1e357f6a14276419579 to your computer and use it in GitHub Desktop.
Save andrii-marushchak/8b57fd72bf1ea1e357f6a14276419579 to your computer and use it in GitHub Desktop.
disable indexation of pages of 'pt-br' language with WPML
$all_pages = array();
/* change language (ensure WPML is properly set up) */
do_action( 'wpml_switch_language', 'pt-br' );
/* building query */
$posts = new WP_Query( array(
'orderby' => 'title', // Corrected from 'sort_column'
'order' => 'ASC', // Corrected from 'sort_order'
'post_type' => 'page',
'posts_per_page' => - 1,
'post_status' => 'publish',
) );
$posts = $posts->posts;
foreach ( (array) $posts as $post ) {
update_post_meta( $post->ID, '_yoast_wpseo_meta-robots-noindex', '1' );
update_post_meta( $post->ID, '_yoast_wpseo_robots', 'noindex,follow' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment