I am trying to diplay a custom post type called “positions”, the problem is it has multiple posts with the same title, taxonomies (job_type, city) , custom fields (company). I want to show only one post if title and all the taxonomies and custom fields data are same. And if title and any other taxonomy or custom field matches it should show only one post if there are multiple posts with those details. I was trying to use the following code but it doenst make any changes to the front end. I am using Bricks builder as the page builder. Looking for a wordpress hook or filter to filter posts
`function filter_duplicate_posts( $query ) {
// Check if the post type is "pay-trackers" and if we're in the main query
if ( $query->is_main_query() && $query->get( 'post_type' ) == 'positions' ) {
// Get the post titles of all published posts
$titles = get_posts( array(
'post_type' => 'positions',
'post_status' => 'publish',
'fields' => 'ids',
'posts_per_page' => -1
) );
// Remove duplicated titles from the array
$titles = array_unique( $titles );
// Set the post__not_in argument to exclude the duplicated posts
$query->set( 'post__not_in', $titles );
}
}
add_action( 'pre_get_posts', 'filter_duplicate_posts' );`