• Resolved henri

    (@riri23)


    Hi I want to filter query only for one category.

    My original filter was :

    add_action('pre_get_posts', 'remove_old_apple');
    function remove_old_apple(&$query)
    {
      	if (is_category()&& empty( $query->query_vars['suppress_filters'] ) ) {
            $today = date("m.d.y");
            global $custom_remove_old_apple;
           	$query->set('meta_key', 'date_maj');
            $query->set('meta_value', $today);
            $query->set('meta_compare', '=');
            }
    }

    And work for all category page, but I want to filter only on the category ID 39 so I try this

    add_action('pre_get_posts', 'remove_old_apple');
    function remove_old_apple(&$query)
    {
     	if (is_category('39')&& empty( $query->query_vars['suppress_filters'] ) ) {
    
            $today = date("m.d.y");
            global $custom_remove_old_apple;
           	$query->set('meta_key', 'date_maj');
            $query->set('meta_value', $today);
            $query->set('meta_compare', '=');
            }
    }

    Why out any success. Do you have some suggestions?
    Thanks for your help

Viewing 1 replies (of 1 total)
  • Thread Starter henri

    (@riri23)

    Found this solution:

    if (($query->query_vars['category_name'] == 'achat-macbook')&& empty( $query->query_vars['suppress_filters'] ) ) {

    I think that you can use the cat ID instead the category name for this hack.

Viewing 1 replies (of 1 total)
  • The topic ‘pre_get_posts question’ is closed to new replies.