Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Hide Category From WordPress Archive Custom Loop

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #196427
    zephyr44
    Participant

    Hi all, I have a theme which I’m trying to customize but I’m a novice with PHP. The front page uses category posts to display spotlights but I want to prevent posts from this category showing up in the news archive/feed. So they shouldn’t be hidden from the site completely, just not appear anywhere else apart form the front page. On the blog page it uses the following loop to get the posts:


    $blog_query = new WP_Query( array( ‘post_type’ => ‘post’, ‘paged’ => $paged ) );
    $temp_query = $wp_query;
    $wp_query = null;
    $wp_query = $blog_query;
    if( $blog_query->have_posts() ) {
    while( $blog_query->have_posts() ) {
    $blog_query->the_post();
    do_action( ‘mytheme_before_post’ );

    There’s a way to do it here but I don’t know to combine the two:
    https://wordpress.org/support/topic/exclude-category-in-side-bar-using-get_archives?replies=5

    #196434
    zephyr44
    Participant

    Update: I don’t know if it’s an ideal way to do it but it seems to work with the following:

    $blog_query = new WP_Query( ‘cat=-5’, array( ‘post_type’ => ‘post’, ‘paged’ => $paged, ) );

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.