Support

Account

Forum Replies Created

  • Hi John,

    Still working on this and try to understand it line by line.

    Regarding this code that you suggested before:

    function my_pre_get_posts($query=false) {
    if (is_admin() || !$query || !is_a($query, ‘WP_Query’) ||
    !$query->is_main_query()) {
    return;
    }

    if (isset($query->query_vars[‘post_type’]) &&
    $query->query_vars[‘post_type’] == ‘post’) {

    $query->set(‘meta_key’, get_field(‘start_date’));
    $query->set(‘meta_type’, ‘DATE’);
    $query->set(‘orderby’, ‘meta_value’);
    $query->set(‘order’, ‘DESC’);
    }
    }
    add_action(‘pre_get_posts’, ‘my_pre_get_posts’);

    1-Is it correct that I used:
    get_field(‘start_date’)

    to get the my custom field value? , or I just should use ‘start_date’ ?

    2- I’ve noticed nothing works unless when I remove the following if clause:

    if (isset($query->query_vars[‘post_type’]) &&
    $query->query_vars[‘post_type’] == ‘post’) {

    When I remove the if clause above, code seems to alter the post order, but couldn’t find out based on what?

    3- Inside ACF plugin panel, and regarding that ‘start_date’ custom form value, I’ve set its “save format” as yymmdd, and display format as dd/mm/yy

    Can it be a possibility that sorting doesn’t work because of display format is dd/mm/yy?

    Many Thanks,
    K

  • Hi John,

    Thanks for reply and sorry for the delay.

    It’s not just one field. It’s a set of fields. I’ve modified the standard post. Please see the following page: http://dailycapital.com.au/canberra_events/venice-the-golden-age-presented-by-oriana-chorale/

    You will notice that almost all fields (start date, end date, address on map, cost, etc) except the event title itself is from ACF. (The event title is actually the post title).

    And no , it’s not a part of a repeater.

    Thank you very much in advance for your help.
    K

  • Thanks John,

    I’ve used the code in my functions.php (as well as reading about it to understand what it is doing), but it doesn’t work. (No sorting happens).

    FYI I’m working on a child theme and put your function into the functions.php of the child theme.

    Any ideas?

    Thanks,
    K

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