what is the best way to change the wordpress blog page post type. by default it fetches the posts with post type is equal to posts but how we can change to to lets say posts type is equal to blog. One way is to add the costume query on the index.php page and selecting the specific post type. Is there any other effective way of doing this ?


You may edit the query using the pre_get_posts action. You can do something like this:


function wpse_218948_search_filter(){
   if( is_page('blog') /* or whatever page it is */ && $query->is_main_query() ){
      $query->set('post_type', 'blog'); # query post type "blog"
      $query->set( 'posts_per_page', -1 ); # display all posts
  • hi i have modified you code accourding to my reeuirement it is working fine but one issue it is only showing 1 post – Mehar Feb 26 '16 at 8:05
  • but i have 4 posts in my blog – Mehar Feb 26 '16 at 8:05
  • Add $query->set( 'posts_per_page', -1 ); to display all posts. Updating my answer. – RRikesh Feb 26 '16 at 8:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.