Support

Account

Forum Replies Created

  • Thanks, John. I amended the function accordingly and this was what I got.

    
    function cpt_date_orderby( $query ) {
     if (!$query->is_main_qieru()) {
      return;
     }
     $orderby = $query->get( 'orderby' );
     if( 'date' == $orderby ) {
        $query->set('meta_key', 'date');
        $query->set('orderby', 'meta_value_num');
     }
    }
    add_action( 'pre_get_posts', 'cpt_date_orderby' );
    

    Did I get it wrong?

  • Hi, ulascansadi. I ran into this problem and successfully got it solved today. Please check whether you used any function where ‘date’ is mentioned. In my case, one of my custom fields is called ‘date’ and then I wrote a function to make the column of this custom field sortable, which caused the problem.

    function cpt_date_orderby( $query ) {
     $orderby = $query->get( 'orderby' );
     if( 'date' == $orderby ) {
        $query->set('meta_key', 'date');
        $query->set('orderby', 'meta_value_num');
     }
    }
    add_action( 'pre_get_posts', 'cpt_date_orderby' );

    The problem lies in line 3, where ‘date’ is value for the parameter. I replaced ‘date’ with a different string, like ‘date1’, and that’s why I solved the problem.

    It seems ‘date’ is a reserved word in WordPress, and should be used carefully.

  • Hi, ulascansadi. I ran into this problem and successfully got it solved today. Please check whether you used any function where ‘date’ is mentioned. In my case, one of my custom fields is called ‘date’ and then I wrote a function to make the column of this custom field sortable, which caused the problem.

    function cpt_date_orderby( $query ) {
     $orderby = $query->get( 'orderby' );
     if( 'date' == $orderby ) {
        $query->set('meta_key', 'date');
        $query->set('orderby', 'meta_value_num');
     }
    }
    add_action( 'pre_get_posts', 'cpt_date_orderby' );

    The problem lies in line 3, where ‘date’ is value for the parameter. I replaced ‘date’ with a different string, like ‘date1’, and that’s why I solved the problem.

    It seems ‘date’ is a reserved word in WordPress, and should be used carefully.

Viewing 3 posts - 1 through 3 (of 3 total)