• Resolved liquiddragon

    (@liquiddragon)


    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;
        }
    • This topic was modified 6 years, 4 months ago by liquiddragon.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter liquiddragon

    (@liquiddragon)

    If I wasn’t such a noob I would have found the solution way faster.

    $query->set(‘meta_query’, $metaquery );

    just had to be
    $query[‘meta_query’] = $metaquery;

    and now it works

    Plugin Author Benjamin Denis

    (@rainbowgeek)

    Glad you found the solution!
    It will probably help other users.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Post Type fitlering’ is closed to new replies.