Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: How to display a post on one page, not home page

Discussion in 'Misc WordPress Requests' started by dineshkashera, Oct 23, 2017.

  1. dineshkashera

    Guest

    Reply To: How to display a post on one page, not home page, by dineshkashera

    Hello,
    You can achieve by using override the action hook.

    add_action( 'pre_get_posts', 'wp_remove_posts_from_home_page' );

    function wp_remove_posts_from_home_page( $query ) {

    //for Home page query
    if( $query->is_main_query() && $query->is_home() ) {
    $query->set( 'category__not_in', array( 2 ) );
    }

    //for travel page
    if( $query->is_main_query() && is_page('travel') ) {
    $query->set( 'category__in', array( 2 ) );
    }

    }

    Note : Don’t forget to replace 2 category id with your travel category id.

    To get more help visit this link https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    I hope it will help you.

    Thanks

    Reply To: How to display a post on one page, not home page
     
    #1

Share This Page

Web Hosting