php display posts by category in wordpress

Solutions on MaxInterview for php display posts by category in wordpress by the best coders in the world

showing results for - "php display posts by category in wordpress"
Ariadna
27 Jun 2017
1$defaults_param = array(
2				'numberposts'      	=> -1,
3				'post_type'        	=> 'post',
4				'category' 			=> 40 ,
5				'suppress_filters'	=> false
6			);
7$get_featured_post = get_posts($defaults_param);
Ricardo
09 Feb 2016
1<?php query_posts('category_name=CATEGORYNAME&showposts=5');
2
3while (have_posts()) : the_post(); ?>
4
5the_title();   // To display the title of all posts that have category name selected 
6
7the_content();   // To display the content of all posts that have category name selected 
8
9
10<?php endwhile; ?>
Ludivine
28 Jun 2017
1$espbc = get_sub_field('add_posts_by_category');
2        
3        $defaults_param = array(
4          //'numberposts'      	=> -1,
5          'post_type'        	=> 'post',
6          'category' 			    => $espbc,
7          'posts_per_page' 			    => 6,
8          'suppress_filters'	=> false
9        );
10        $catPost = get_posts($defaults_param);
Ida
24 Nov 2020
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
list posts of category wpwordpress get category posthow to display recent posts from a specific category in wordpressget posts by category id wordpressget post for category wordpresshow to display all posts from a category wordpressget post wordpresslist posts by category wordpressget category of posts wpget posts by categoryget category name in single post wordpressget posts with categoryhow to get posts by category in wordpresswp query get posts by categoryhow to get post in wordpress by category nameget all posts by category id wordpressdisplay of posts page wordpress show post category name wordpresshow to get post in wordpress by using category name in wordpress page templateget wordpress posts by category nameget post category wordpress wordpress get post category phpwordpress display realted post with categorywordpress only show posts from specific categoryphp get posts by categorywp get post category namewordpress get posts from all categorydisplay post by category in wordpresshow get post by category inwphow to get post category list in wordpressdisplay post of specific category with choose in wordpress developmentget the category of post wordpresswordpress com show posts categorywordpress get posts from a categorydisplay specific category post in wordpressshow category name in post wordpressget posts in categorywordpress query posts get all posts with current categorywordpress show all posts in category pagewordpress get posts with categorywordpress get posts in categoruwordpress sql get posts in categoryget category name from post wordpressdisplay category posts on page wordpresswp get posts argsget posts by category wordpress functionhow to find out all post of category in wordpresswp get posts by categorywp get postwordpress category show all postshow to make a page for a category posts in wordpressdisplay posts from category wordpressquery posts by category wordpressdisplay posts by category wordpress on a pagewp get posts of categoryget wordpress posts by categoryget post category names by id wordpressget postsshow wordpress post on page by categoryget category post wordpressshow all posts of a specific category on the home page in wordpress themewordpress post categorywordpress post get the categoryeget posts 28 29wordpress list of posts on page by categoryhow to show category post show on page wordpressshow posts of one category wpget posts with category id wordpressgetting current category all post category in wordpresswordpress only show posts from selected categoryhow to get post category name in wordpressget category in the postwordpress display post category namehow to get post category in wordpresshow to display posts from a specific category on specific pages in wordpresshow to get category of post in wordpressget posts in category wordpressget posts by post categoryget post based on category name wordpressget wordpress posts by category name 21display posts by category wordpressget posts 28 29 wordpresswordpress posts category allget posts based on category wordpresswordpress get category by get postget posts of specific category wordpresswordpress display posts from specific category on pageget posts by category idwordpress get post by category nameget category postswordpress get posts by category idget posts category name php wordpressget posts get categoryget posts 28 24args 29get post by category wordpressget all posts from category wordpressphp wordpress show the category of a postdisplay posts by category wordpress on different pageget posts all postswordpress view posts by categorydisplay posts by category wordpress on a page prettywordpress show posts on page by category in customdisplay posts under different category wordpressget posts categoryget posts wordpress allhow to get current post category name in wordpresswordpress get posts by categoriesget the category of a post wordpressget posts by category slughow to show category posts under selected category of the post is from 3 categories wordpresswordpress get category name in single postget posts of a category wordpresswordpress how to display category posts on a pagedisplay category of posts wordpresshow to list posts by category in wordpresswordpress show posts from category on page theme developmentwordpress get posts where categoryget the post category name wordpressget posts by wordpress categoryhow to show specific post content in category page on wordpresswordpress get posts by titlesshow posts in category with a tag wordpressget category name post wordpressphp get category with postswordpress page posts specific categorydisplay posts in different category wordpressshow posts from specific category wordpress pluginget posts 28get posts args wordpressget post category name in wordpressget category of postsfind posts with categorywordpress get posts by categoryget post argscustom wordpress widget so show posts from specific categoryget posts category by id in wordpressget posts wordpresswordpress get posts of certain categorywordpress get postswordpress get the category name of a post wp queryget posts by category id in wordpresswordpress display other posts from same categorywp display post categorywordpress list posts in specific pagewordpress display post categoryphp display posts by category in wordpressposts category list wordpresshow to display category posts in wordpress pagewordpress get posts of categorywordpress display posts by categorywp only show posts list of certain categoryget posts categoryget post by category id in wordpressget posts by category slugwordpress get post categorywordpress php get posts of specific categorydisplay post category wordpresswordpress query posts by categorywordpress get post category listget post category name wphow to show particular category in specific page of wordpressshow post from specific category wordpresshow assign get post category name in wordpressshow all posts from categorydisplay post of specific category in wordpress developmentwordpress get post by categoryquery for getting posts with category in wordpresshow to get category posts number in wordpressget posts by category wordpresswordpress display all posts in a category on a pagewp list posts by categoryget the category name wordpress single postwordpress get posts examplewordpress get posts from categoryget posts based off user wordpresswordpress from posts list get termshow to get category name by post id in wordpressget category name by post id wordpress wordpress get all posts by category show specific category post wordpressshow wp post category php function get posts 28 29how to show some particular category post in wordpress home pagedisplay post of specific category in wordpresswordpress posts from all categorywp get posts from categorywordpress get category name get postswordpress list posts by category on pagewp query posts for categoryget posts exampledisplay post category name wordpresswordpress list category postsdisplay category name of post wordpresswordpress display posts by category nameshow posts from specific category wordpress blog pageget posts argumentsget posts by category in wordpresshow to display post from specific category wordpressget posts by category name wordpresswordpress get category from postget category of post wordpressdisplay post from specific category wordpresshow to get particular category post in wordpresshow to display recent posts from all category wordpresswordpress display popular posts on page by categorywordpress get post category namewordpress page with category posts posts by category id wordpresswordpress get posts by category slugwordpress display category and postsdisplay posts by category in wordpresswordpress query only posts from categoryget posts from category wordpresspage to display category posts wordpresshow to display post and there category in wordpresswp show posts in category by name onlyshow posts by category wordpresswordpress query to get posts by categorydisplay the category of a post in wordpresswordpress get posts in categorywordpress load posts from categorywordpress get posts from specific categorieswordpress show all posts from category on pagewordpress display 2 category posts on pagewordpress get post categorydisplay posts from specific category on a wordpress pagehow to get posts using category namehow to display category name posts on wordpress pagesdisplay post category in wordpresslist wordpress posts by categorywp get posts in category 24this 5b 27publishedblog 27 5d 3d 24post 3egetallpublishedpost 28 29 3bget post category name wordpressget post with category in wordpresswordpress get category of postwordpress display posts on page by categoryget posts user role wordpresswordpress posts by category menuwordpress get posts by category pythonwordprss get posts by categorylist posts from all category wordpress functionget posts of particular category in wordpressget category name in post wordpressmysql query for getting posts with category in wordpresshow to display category posts on wordpress pageswordpress post get categoryget the category on postlatesst posts get in wpwordpress how to display category of the postwordpress show posts from category on pagewordpress show posts in pagelist posts by category id wordpress wordpress widget posts from categorywordpress get posts of certain category for a themeget posts include exampleget post by category name in wordpressshow posts from specific category wordpresswordpress show category posts on pageget category name wordpress postwordpress get all posts of current categorywordpress get all posts of this categorywordpress get posts by category namephp display posts by category in wordpress