wordpress display posts from specific category on page

Solutions on MaxInterview for wordpress display posts from specific category on page by the best coders in the world

showing results for - "wordpress display posts from specific category on page"
Emily
15 Jan 2021
1The argument isn't category, it is cat. Your query fails because you are using an argument that doesn't exist.
2
3$args = array(
4  'post_type' => 'post' ,
5  'orderby' => 'date' ,
6  'order' => 'DESC' ,
7  'posts_per_page' => 6,
8  'cat'         => '3',
9  'paged' => get_query_var('paged'),
10  'post_parent' => $parent
11); 
12$q = new WP_Query($args);
13if ( $q->have_posts() ) { 
14  while ( $q->have_posts() ) {
15    $q->the_post();
16    // your loop
17  }
18}
19Notice that I have converted your query_posts() into a new WP_Query object. Do not use query_posts(), ever. Even the Codex states so.
20
21Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination). Any modern WP code should use more reliable methods, like making use of pre_get_posts hook, for this purpose.
22
23http://codex.wordpress.org/Function_Reference/query_posts
24
25Also note that I removed unnecessary PHP opening and closing tags and formatted the code for better readability. That alternative control structure syntax is a formula for failure, in my experience.
queries leading to this page
wordpress widget posts from categoryhow to display post from specific category wordpresswordpress how to display category posts on a pagehow to display all posts from a category wordpressshow posts from specific category wordpress blog pagewordpress query only posts from categorywordpress display other posts from same categorydisplay post of specific category in wordpress developmentwordpress show all posts from category on pagedisplay category posts on page wordpressphp display posts by category in wordpresswordpress show all posts in category pagedisplay posts by category wordpress on different pageshow posts from specific category wordpresswordpress view posts by categorywordpress get posts by titlesshow post from specific category wordpressdisplay posts from category wordpresswordpress get posts of categorypage to display category posts wordpresswordpress get posts in categorydisplay specific category post in wordpresswordpress category show all postsdisplay post from specific category wordpresswordpress display popular posts on page by categorywordpress display posts by category namehow to show category post show on page wordpresscustom wordpress widget so show posts from specific categorywordpress list of posts on page by categoryshow wordpress post on page by categorywordpress get posts from specific categoriesdisplay category of posts wordpressshow posts of one category wpwordpress page posts specific categorywordpress only show posts from specific categoryshow specific category post wordpresswordpress how to display category of the posthow to show specific post content in category page on wordpresshow to display category posts in wordpress pagewordpress show posts from category on page theme developmentwp only show posts list of certain categorywordpress page with category postswordpress show category posts on pageshow posts from specific category wordpress pluginhow to make a page for a category posts in wordpresswordpress display realted post with categoryshow all posts of a specific category on the home page in wordpress themewordpress display posts on page by categorywordpress com show posts categoryget posts based on category wordpresshow to display recent posts from a specific category in wordpressdisplay posts by category wordpresswordpress display posts from specific category on pagewordpress display posts by categorydisplay posts by category wordpress on a pagewordpress display 2 category posts on pagedisplay posts under different category wordpressdisplay post of specific category with choose in wordpress developmentshow posts by category wordpresshow to display category name posts on wordpress pageshow to show particular category in specific page of wordpressdisplay posts in different category wordpresswordpress list posts in specific pagewordpress get posts by category pythonhow to display category posts on wordpress pagesget posts of specific category wordpresswordpress show posts on page by category in customwordpress php get posts of specific categorywordpress list posts by category on pagedisplay posts by category wordpress on a page prettywordpress load posts from categorydisplay posts by category in wordpresswordpress get posts of certain category for a themewordpress show posts from category on pagehow to display recent posts from all category wordpressshow posts in category with a tag wordpressget posts of particular category in wordpresshow to show some particular category post in wordpress home pagedisplay posts from specific category on a wordpress pagewordpress only show posts from selected categorydisplay post of specific category in wordpresshow to display posts from a specific category on specific pages in wordpresswordpress posts from all categorydisplay of posts page wordpress wordpress display category and postswordpress display posts from specific category on page