-
This is a continuation of this support ticket.
Hi, I am ready to start troubleshooting again. I tried numerous things, but I think I know what the problem is here. Since I have a WordPress website where I use Translatepress each of the job listings (posts) on my site have a double URL. One for English jobs, one for Dutch jobs. With some code I was able to make sure only one of the jobs is set to index and the other one to noindex, as they are not translated and I want to avoid duplicate content.
So I get this done by this code:
add_filter( 'rank_math/frontend/robots', function( $robots ) { $post_id = get_the_ID(); if ( get_post_type( $post_id ) === 'job_listing') { $current_url = home_url( add_query_arg( array(), $wp->request ) ); $terms = wp_get_post_terms( $post_id, 'job_languages', array( 'fields' => 'names' ) ); if ( in_array( 'Nederlands', $terms ) && strpos( $current_url, '/en/' ) !== false ) { if ( isset( $robots['index'] ) && $robots['index'] === 'index' ) { $robots['index'] = 'noindex'; } } elseif ( !in_array( 'Nederlands', $terms ) && strpos( $current_url, '/en/' ) === false ) { if ( isset( $robots['index'] ) && $robots['index'] === 'index' ) { $robots['index'] = 'noindex'; } } } return $robots; });
This works perfectly
In my sitemap however, still both URLs are submitted. I tried a lot of things, based on the code you guys helped me write a year ago to immediately filter out filled jobs from our sitemap, which also works perfectly.
add_filter( 'rank_math/frontend/robots', function( $robots ) { if(get_post_type() == 'job_listing' && get_post_meta( get_the_ID(), '_filled', true )) { $robots["index"] = 'noindex'; $robots["follow"] = 'follow'; } return $robots; });
I messed around with that filter by filtering out the posts with noindex, but no success.
I think the reason is that one post will always have 2 separate URLs and I only want to submit one of these URLs (the one which says index) to the sitemap and as soon as it becomes noindex it should be deleted from the sitemap. So when in the function I look for the post ID, I will always have one URL with index and one with noindex for the same post ID.
Any idea how I can get this done? I can give you access to our development environment to troubleshoot. But you should know that each page there is set to noindex to avoid Google from indexing our dev environment. This might making troubleshooting more difficult, but in essence each job you can find in our sitemap should be there once per Post ID, now I have doubles.
Thanks!
The ticket ‘How to filter one of two multilingual posts with same ID out of the sitemap?’ is closed to new replies.