1

I found this wonderful code that allows you to create a link to the most recent post in a category, and it's perfect for what I need. I tried it out, it works great. However, it doesn't include posts from Custom Post Types. (I'm using Wordpress Pods plugin http://wordpress.org/plugins/pods/ to create my CPTs.) How do I modify this to include the posts from my custom post types? Any help is appreciated. Thanks!!

Original thread: How can I link to the most recent post in a category?

1

As long as Pods creates standard custom post types, you can simply update the arguments passed to WP_Query . The$post_type parameter will allow you to filter the results based on the specified post type (string) or post types (array).

$latest = new WP_Query( array(
    'category_name' => $request->query_vars['category_name'],
    'posts_per_page' => 1,
    'post_type' => array ( 'post', 'your_custom_post_type' ),
) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.