Support

Account

Home Forums General Issues Retrieve fields for post type in home page Reply To: Retrieve fields for post type in home page

  • May this is, what you are looking for. First, the get_posts() function gets the posts from the post type “product” ordered by date with the latest date first and returning only the first result by ‘numberposts’ => 1. Then get the field value of that post using its ID.

    $latest_post = get_posts(array(
        'numberposts' => 1, // restrict result to only the latest post
        'post_status' => 'publish',
        'post_type' => 'product',
        'orderby' => 'date',
        'order' => 'DESC'
    ));
    
    $prev = get_field( 'pref', $latest_post[0]->ID );