Support

Account

Home Forums Feedback Сustom pagination in the custom field

Helping

Сustom pagination in the custom field

    • qnak

    • November 26, 2019 at 5:46 am

    Hello
    I encountered the problem of displaying custom records in pages by date. I have approximately 400 posts from 2017 to 2019. The date is in a custom field and I take it using the operation $year = date("Y", strtotime(get_field('letter_sent'))); . All posts are displayed on this request

    $posts = get_posts(array(
        'post_type'			=> 'letters',
        'numberposts'	    => -1,
        'meta_key'          => 'letter_sent',
        'meta_type'         => 'NUMERIC',
        'orderby'           => 'meta_value',
    ));

    .
    It is necessary to create a page for 2019 and display entries in which are in the field 2019, for 2018 and so on. Tell me how to implement this since I can’t find a clear answer.
    (sorry for google translate)

    • Wish

    • November 27, 2019 at 4:22 pm

    Hey,
    I really didn’t get the question, but rather than filtering it in the query, you can use this.

    $posts = get_posts(array(
        'post_type'			=> 'letters',
        'numberposts'	    => -1,
    ));
    foreach($posts as $post)
    {
    if(get_field('letter_sent', $post->ID) == '2019')
    {
    //your code
    }
    }

    Also the meta_key is not same when acf saves it. Try enabling the Custom fields option in the Screen options. You will get the idea how acf saves the custom fields.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.