Stream Page Posts not in TAGS' Results

Community Forums Forums Design Tips and Tricks Stream Page Posts not in TAGS' Results

This topic is: not resolved

This topic contains 3 replies, has 2 voices, and was last updated by  francky 10 months, 3 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #55777

    francky
    Participant
    Post count: 39

    I have the code below to add a Stream Page in my website but the problem I have is that when accessing a certain TAG Page eg. http://www.example.com/tag/election , a post with tag “election” in the stream doesn’t show up! But if there is any normal blog post with the same tag, it shows up! The problem is only with the “Stream Posts”.
    How can I have this work? Thank you in advance!

    //* Create stream custom post type
    add_action( 'init', 'stream_post_type' );
    function stream_post_type() {
        register_post_type( 'stream',
            array(
                'labels' => array(
                    'name' => __( 'The Stream' ),
                    'singular_name' => __( 'Stream' ),
                ),
                'has_archive' => true,
                'hierarchical' => true,
                'taxonomies' => array( 'post_tag' ),
                'public' => true,
                'rewrite' => array( 'slug' => 'stream' ),
                'supports' => array( 'title', 'editor', 'custom-fields', 'genesis-seo', 'thumbnail', 'comments' ),
            )
        );
    }
    http://tags, stream page, stream
    #60367

    francky
    Participant
    Post count: 39

    Anyone who can help me with this please?

    #60430

    Norcross
    Participant
    Post count: 2

    by default, the tag archive page won’t include any post type other than posts. you need to include your post type in there with a pre_get_posts filter. This code should do it.

    function stream_to_tag_loop( $query ) {
    	
    	// we don't want this running on the admin side
    	if ( is_admin() )
    		return;
    
    	// include our stream type on tag pages
    	if ( is_tag() && $query->is_main_query() ) {
    
    		$query->query_vars['post_type']	= array( 'post', 'stream' );
    
    		return;
    	}		
    		
    }
    
    add_action ( 'pre_get_posts', 'stream_to_tag_loop' );
    #60454

    francky
    Participant
    Post count: 39

    WoW!! PERFECT!
    It worked like a charm! WoW!

    Thank you very much @Norcross

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.