Custom Post Type fitlering
-
I’m trying to filter out some custom post types based on their metadata. I have an expiry date on the custom post type and I have the default query as well as elementor fitlers working fine so that they don’t show the posts. But I don’t seem to be able to get SEOPress to work, it just errors out. Here is the code I have for the filter
public function sp_sitemaps_single_query($query, $cpt_key) { //Default Query //$args = array( 'posts_per_page' => 1000, 'order'=> 'DESC', 'orderby' => 'modified', 'post_type' => $cpt_key, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_seopress_robots_index', 'value' => 'yes', 'compare' => 'NOT EXISTS' ) ), 'fields' => 'ids', 'lang' => '' ); if ( $cpt_key == $this->post_type_name ) { //Wordpress seems to need the date in Y-m-d format to filter it. Hence the below format. $today = date('Y-m-d'); $metaquery = array( array( 'key' => uglify($this->post_type_name . '_' . 'Page Expiry Date'), 'value' => $today, 'compare' => '>=', 'type' => 'DATE' ) ); $query->set('meta_query', $metaquery ); } return $query; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Custom Post Type fitlering’ is closed to new replies.