• Resolved gillinghamjamie

    (@gillinghamjamie)


    Hi there,

    I’m wondering if it’s possible to add custom post types to “Latest Posts”? Right now, it isn’t pulling a custom post type I use quite often called “rcno_review”.

    Thank you!

    Jamie

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Calin Vingan

    (@calinvingan)

    Thread Starter gillinghamjamie

    (@gillinghamjamie)

    Thanks, Calin. I came across that and tried the solution but the code seems broken when I try to add it to functions.php, specifically, 'orderby’ => 'title',

    add_filter('abh_author_latest_posts', function($query){
     
    $args = array(  
            'post_type' => 'services',
            'post_status' => 'publish',
            'posts_per_page' => 5, 
            'orderby’ => 'title', 
            'order’ => 'ASC', 
        );
    
        return new WP_Query( $args );
    });
    Thread Starter gillinghamjamie

    (@gillinghamjamie)

    @calinvingan Following up on this, please let me know if you have any alternate ideas as the snippet you provided doesn’t seem to be working.

    Plugin Contributor Calin Vingan

    (@calinvingan)

    Be careful for the apostrophe to not be converted:

    add_filter('abh_author_latest_posts', function($query){
     
    $args = array(  
            'post_type' => 'services',
            'post_status' => 'publish',
            'posts_per_page' => 5, 
            'orderby' => 'title', 
            'order' => 'ASC', 
        );
    
        return new WP_Query( $args );
    });

    I checked the code and it’s correct.

    Thread Starter gillinghamjamie

    (@gillinghamjamie)

    This worked! Thank you.

    Thread Starter gillinghamjamie

    (@gillinghamjamie)

    @calinvingan actually, sorry, now it’s fetching all of the latest posts for that post type regardless of author.

    I’m looking to just add a new post type (rcno_review) so that that post type is fetched for each author.

    Plugin Contributor Calin Vingan

    (@calinvingan)

    add_filter('abh_author_latest_posts', function($query){
        global $post;
    
        if(isset($post->ID)){
            $args = array(
                'post_type' => 'rcno_review',
                'author' => $post->post_author,
                'post_status' => 'publish',
                'posts_per_page' => 5,
                'orderby' => 'title',
                'order' => 'ASC',
            );
    
            return new WP_Query( $args );
        }
    
        return $query;
    });
    • This reply was modified 2 years, 4 months ago by Calin Vingan.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom post types in latest posts’ is closed to new replies.