Support

Account

Home Forums General Issues Custom Query Filter on widgets

Helping

Custom Query Filter on widgets

  • Hi,
    i need to show and filter posts on a widget by an ACF named ‘custom_date’.
    This code works on a page but it doesn’t works on a widget.

    $new_query = array(
    ‘post_type’ =>’post’,
    ‘meta_query’ => array(
    ‘key’ => ‘custom_date’,
    ‘value’ => date(‘Y-m-d H:i:s’),
    ‘type’ => ‘DATETIME’,
    ‘compare’=> ‘<‘)
    );

  • SOLVED: It works by adding some other conditions to the query like that:

    $new_query = array(
    ‘meta_key’=>’custom_date’,
    ‘orderby’=>’meta_value’,
    ‘order’=>’ASC’,
    ‘post_type’ =>’post’,
    ‘meta_query’ => array(
    ‘key’ => ‘custom_date’,
    ‘value’ => date(‘Y-m-d H:i:s’),
    ‘type’ => ‘DATETIME’,
    ‘compare’=> ‘<‘)
    );

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

You must be logged in to reply to this topic.