loop – Update query based on CPT / Post Type, show all sorted by date

Question

I’m trying to accomplish something similar and read through Vayu’s code, which is super elegant, but it doesn’t accomplish what I need.

Specifically, I need to be able to include a different template part for each post type (they have slightly different content) as well as add/update an $arg for the WP post (that is not a CPT) to target a specific cat

What I’m trying to accomplish is this (just in logic format with $args above):

    $my_post_types = array( 'auctions', 'liquidations', 'inventory',  'post' );

    // set args for ALL posts
    $args = array(
        'post_type'     => $my_post_types,
        'orderby'       => 'date',
        'order'         => 'DESC',
        'post_status'   => 'publish',
    );
    
    Now we loop through posts (while loop)

    IF 'post_type == auctions' 
        add number_posts to $args from ACF field for this post type
        get_template_part( 'template-parts/card', 'auction' );  

    IF 'post_type == liquidations' 
        add number_posts to $args from ACF field for this post type
        get_template_part( 'template-parts/card', 'liquidations' );  

    IF 'post_type == inventory' 
        add number_posts to $args from ACF field for this post type
        get_template_part( 'template-parts/card', 'inventory' );  

    IF 'post_type == post' 
        add 'cat => 304' to $args 
        add number_posts to $args from ACF field for this post type
        and get_template_part( 'template-parts/card', 'studies' );  

The goal is to show all of the CPTs and Posts, in the qty set for each type in the admin, sorted by date, on one page. I need to update/add to the $args for each of the post type loops….

0
revive 8 months 2021-12-17T11:12:58-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse