We're merging with GenerateBlocks! Learn more here.

[Support request] Showing posts from a tag?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Showing posts from a tag?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #36643
    Ema
    Participant

    Hello! 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

    #36647
    elvin
    Moderator

    Hi 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. ๐Ÿ˜€

    #36650
    Ema
    Participant

    Thanks for your reply Elvin! I’ll give this a try and get back to you. Looking forward to GP Blocks merge ๐Ÿ˜€

    #36652
    Ema
    Participant

    Oh, Where do I find the ‘list id’?

    • This reply was modified 3 months ago by Ema.
    #36659
    Fernando
    Participant

    Hi Ema,

    It can be found here: https://share.getcloudapp.com/p9uXqWwn

    Hope this helps! ๐Ÿ™‚

    #36666
    Ema
    Participant

    Thank you Fernandoaz!

    • This reply was modified 3 months ago by Ema.
    #36670
    Fernando
    Participant

    Youโ€™re welcome Ema! Glad to be of assistance! Feel free to reach out anytime if youโ€™ll need assistance with anything else. ๐Ÿ™‚

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.