WordPress.org

Ready to get started?Download WordPress

Forums

Show custom post type with the same category (2 posts)

  1. Blizzie
    Member
    Posted 2 years ago #

    I've read tutorials about showing custom post type with the same category but it seems that all I get was the same posts from the main loop. I want to display custom post type named 'content_block' (it's from the Custom Post Widget) in the sidebar. Here's my code:

    $custom_event = new WP_Query(array('post_type' => 'content_block', 'posts_per_page' =>5));
    while ($custom_event->have_posts() ): $custom_event->the_post();
    echo the_title();
    echo '</br>';
    echo the_content();
    echo '</br>';

    endwhile;

    It doesn't display the custom post type content_block but instead the post from the main loop (which is another custom post type)
    Please help me. :(

    Thank you in advance.

  2. Blizzie
    Member
    Posted 2 years ago #

    Maybe it is conflicting with this:

    add_filter( 'pre_get_posts', 'my_get_posts' );

    function my_get_posts( $query ) {
    if ( is_home() )
    $query->set( 'post_type', array( 'memorandum' ) );

    return $query;
    }

    I have that code in the function.php

    Please reply asap :(

Topic Closed

This topic has been closed to new replies.

About this Topic