Home › Forums › Pro Support › Showing posts from a tag?
Tagged: custom-post-types
- This topic has 6 replies, 3 voices, and was last updated 1 year, 7 months ago by
Fernando.
-
AuthorPosts
-
February 21, 2022 at 11:03 am #36643
Ema
ParticipantHello! is there a way that I can show posts from a Category that spans all 4 of my CPTs?
My set-up is, that I have 4 CPTs, with Categories and Tags.Each CPT has the same tags and cats.
The categories are under the taxonomy of ‘Topics’. If I was to add a further category under Topics – say “Featured” (adding this category to all CPTs)…
Is there a way I can pull ALL posts with the category “Featured”, from all my CPTs at once?
The client wants to show a carousel of the latest posts from each of the 4 subjects.
I can see that I can only show from “Featured” from on CPT at a time, atm.Best Ema
February 21, 2022 at 8:07 pm #36647elvin
ModeratorHi Ema,
Hello! is there a way that I can show posts from a Category that spans all 4 of my CPTs?
It should be possible but we’ll have to resort to a bit of modification to the plugin’s file and a bit more custom PHP for filtering the query.
Make this change in your wp-show-posts.php file: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de
The PHP will be something like this:
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 123 === $settings['list_id'] ) { $args['post_type'] = array('post','custom_post_type_slug_1','custom_post_type_slug_2','custom_post_type_slug_3'); $args['tax_query'] = array( 'relation' => 'OR', array( 'taxonomy' => 'topics', 'field' => 'slug', 'terms' => array( 'featured','another-topic-term' ), ) ); } return $args; } );
Change
123
to the WPSP list ID you’re displaying this on and change$args['post_type'] = array('post','custom_post_type_slug_1','custom_post_type_slug_2','custom_post_type_slug_3');
to add the post type slugs.You’ll also have to change
'terms' => array( 'featured','another-topic-term' ),
array slugs to featured + other “Topics” term slugs you want to include. ๐February 22, 2022 at 5:49 am #36650Ema
ParticipantThanks for your reply Elvin! I’ll give this a try and get back to you. Looking forward to GP Blocks merge ๐
February 22, 2022 at 5:51 am #36652Ema
ParticipantOh, Where do I find the ‘list id’?
-
This reply was modified 1 year, 7 months ago by
Ema.
February 22, 2022 at 7:10 pm #36659Fernando
ParticipantFebruary 23, 2022 at 4:42 am #36666February 23, 2022 at 7:05 pm #36670Fernando
ParticipantYouโre welcome Ema! Glad to be of assistance! Feel free to reach out anytime if youโll need assistance with anything else. ๐
-
This reply was modified 1 year, 7 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.