Home › Forums › Pro Support › Including more than one post type
Tagged: CPTs
- This topic has 20 replies, 5 voices, and was last updated 1 year, 10 months ago by
Joon.
-
AuthorPosts
-
March 17, 2021 at 3:11 am #28150
Joon
ParticipantThanks!
That worked great!
Is it also possible for the query to fetch posts from two different category taxonomies? The Events Calendar uses it’s own category taxonomy called “tribe events cat”. I tried to modify the query but came up short. This is what I came up with but it does not show anything… I guess this code requires that both of the arguments are true?
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if(16270 === (int)$settings['list_id']){ $args['post_type'] = array('post','tribe_events'); $args['category_name'] = 'ajankohtaista'; $args['tribe_events_cat'] = 'ajankohtaista'; } return $args; }, 15, 3 );
March 17, 2021 at 4:29 am #28156Joon
ParticipantAnd I just want to say I really appreciate the help!
The end result I’m trying to achieve is one where the user can add regular posts, that are automatically seen on the frontpage list. And when needed, they can choose a specific category for an event if they want the event to be seen in this same list.
I realized that categories would be better suited to achieve this. The regular posts have a default category that is added to all posts. Events do not, but the user could add the event to a category if they want to add it to the frontpage.
But the problem is that The Events Calendar uses their own taxonomy for their categories, so I’m not sure if you can achive this in a query like this?
March 17, 2021 at 5:09 pm #28192elvin
Moderator$args['tribe_events_cat'] = 'ajankohtaista';
This won’t work. There’s no
tribe_events_cat
in the WP codex for wp_query.What you need is the taxonomy parameters: https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters
See my example code on taxonomy parameters here:
https://wpshowposts.com/support/topic/show-posts-from-a-category-and-a-tag-2/#post-26833March 18, 2021 at 1:13 am #28222Joon
ParticipantThank you!!
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if(16270 === (int)$settings['list_id']){ $args['post_type'] = array('post','tribe_events'); $args['tax_query'] = array( 'relation' => 'OR', array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array( 'category_name' ), ), array( 'taxonomy' => 'tribe_events_cat', 'field' => 'slug', 'terms' => array( 'category_name' ), ), ); } return $args; }, 15, 2 );
This is the code I ended up with and it seems to do the job 🙂 If someone is using The Events Calendar and wants to pull single events to a WPSP list by adding it to a specific category, just rename the category_name in the code above.
March 19, 2021 at 2:08 pm #28266Joon
ParticipantSo the code above works fine but I have a last question. Would it be impossible to prioritize some categories over others?
95% time we will publish traditional posts/news but when we post stuff from these two other categories, it would be nice if we could “pin” these posts there for a while. Right now the only way to do that is to keep changing the date of these posts to keep them showing in the list. And because these are custom post types, the sticky feature in WordPress is not working. So would there be any to get post from these specific categories to “bypass” the traditional posts?
There were some discussions here about prioritizing a specific category but I did not find a final solution…
https://wpshowposts.com/support/topic/show-posts-in-current-category-and-specific-tag/March 20, 2021 at 6:42 am #28279Joon
ParticipantA “sticky featured tag” would also serve the same purpose..
-
AuthorPosts
- You must be logged in to reply to this topic.