0

I have three blog pages named 'blog' 'page_2' 'page_3' and four categories named 'cat1' 'cat2' 'cat3' 'cat4' in WordPress. Here 'blog' is the default blog page. Problem is when i submit a post it posted to three blog pages automatically.

How can i post

  1. all four category in 'blog' page
  2. 'cat_2' for 'page_2'
  3. 'cat_3' for 'page_3'

I have found below code in WordPress. But it only works for excluding category from main blog page ( is_home) not for any other page.

function exclude_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '-1,-1347' );
    }
}
add_action( 'pre_get_posts', 'exclude_category' );
  • This script alters the query, for when displaying the post, and won't change categories when saving the post to the database. Are you entering your posts via wp-admin? If so, there is normally a "categories" box in the right hand column, (this can be turned off and back on) to select the desired categories. – De Coder Aug 28 '18 at 16:03
  • I am entering my posts via wp-admin and using dotted theme from themeforest. I have created duplicate copy of blog page named 'blog' 'page_2' and 'page_3'. Now after entering any post it showed in the three pages which is my problem. I need to make post for specific page and specific catagory. – Habib Aug 28 '18 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.