How can I query posts from any category?

How can I display posts query from any category? For example, I want to show post using two column layout.

  • The first layout will show one post with big thumbnail and title.
  • The second layout will show four posts with small thumbnail and title.

How can I query posts from any category?


You can run below query to get result of that specific category

//get result by category id here 4 given as category_id
$query = new WP_Query( array( 'cat' => 4 ) );
//or you can get result by category name here test given as category name
$query = new WP_Query( array( 'category_name' => 'test' ) );
//then run the wp loop
if ( $query->have_posts() ) :
    while ( $query->have_posts() ) : $query->the_post();
     //write your custom code here

Category: post thumbnails Time: 2016-07-28 Views: 0

Related post

  • How can I query posts from multiple roles? 2011-07-16

    I'm using the code below from another answer to query posts from 1 custom role, eg "friends". I thought I could just comma separate the roles to list posts from more than one role, but this didn't work. Is there another way I can write it? I've

  • How to get Recent Post From Each Category with Thumbnail? 2011-06-03

    For Example,Now I have 3 Categories Like Food,Transport,Technology.Under These Categories I have Many Posts.Now I Want To Show the Latest Post From Each Category.{How to get Recent Post From Each Category with Thumbnail?}Is This is Possible? I Think

  • How can I query posts with newly uploaded images? 2012-09-24

    I have a custom post type for events. A couple of days after each event photos are sometimes uploaded and attached to the event they were taken at. I want to highlight these image gallerys somewhere on my site, displaying them under a headline "Recen

  • How can I extract sentences from any search engine? 2013-09-26

    For people who are learning a foreign language it is very helpful to see usage of particular words in a sentence. For example you want to see different inflections of a verb. I used to look at usage of words in imdb > quotes search section, it almost

  • How to filter out post from a category not its subcategory in wordpress dashboard 2015-12-15

    I have a category named "SERVICES" and I have added three subcategories for "SERVICES" category. I have added three posts for the category "SERVICES" and several posts for the subcategories. Some of my posts don't belong to t

  • How to get latest posts from each category in regular order 2014-03-19

    let's say I have a main query and it displays posts from Movies and Music categories. I want the query to show always 5 latest posts from Movies and 5 latest posts from Music category. When I create a new post in Movies category the query will show 6

  • How to display related posts from same category? 2011-10-02

    Is it possible to display related posts from same category as the current post? --------------Solutions------------- One possibility: $related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 5, 'post__not

  • how can i get posts from custom post type particular taxonomy category 2011-07-18

    I have registered custom post type Article in my template using register_post_type function. and i also having taxonomy category for this article posts. Here i want to filter the posts under particular category. using query post How can i do this Tha

  • How can I get posts from 9/13/11 to today with SQL? 2012-01-18

    I have been working with a client to redesign his site and we are at the stage where we are going live, except I'm running into a little problem. Time is of the essence, as the deadline is mid-day tomorrow. Since I began working on the site, he sent

  • How can i count post from my post type taxonomy 2013-01-10

    How can i get the count for published post from my custom post type , from my taxonomy. I have Custom Post Type : trailers, Taxonomy : trailere-noi <?php $items = get_posts( array( 'post_type' => 'trailers', 'numberposts' => -1, 'taxonomy' =>

  • How can I limit connections from any IPs but localhost using xinetd? 2014-10-13

    There is a xinetd service. Users connect to it from their workstations. How can I limit them to use only one connection per IP, but keep unlimited connections from localhost? I know there is per_source option, but it does not make a difference betwee

  • SOLVED - How can you query posts by advance custom field when the value is a serialized array? 2015-07-21

    Bottom for resolution Im going crazy I think. I cannot figure this out for the life of me. I have an advanced custom field that is a select box. The select box has multiple values and allows for multi-selections. I made 1 post and multi-selected 3 va

  • how to get 1 post from current category's sub categories 2015-09-19

    I want to show a list of current category's subcategories with their latest past in subcategories I have categories like this >> Electronics >> Mobile >> Android >> iphone >> Tabs >> LCD >> Camera >> laptops

  • How can I share posts from GoogleReader to Google+ 2011-07-20

    Possible Duplicate: Send to Google Plus from Reader How can I add Google+ to the custom "Share" items in GoogleReader? According to this question and lack of resolution, it is not possible? David Vielmetter suggests that dragging-and-dropp to th

  • How can I copy posts from my old (but still active) blog without SEO penalty? 2016-06-28

    I have had an old blog (which is still active) where I published some articles which I also want to publish on the new blog? How can I do this without SEO penalty? --------------Solutions------------- I am assuming that you are saying that you are wo

  • How to show 5 posts from specific category on related page? 2013-10-23

    I'm not familiar enough with wordpress to ask the question directly, so please bare with me as I explain what I'm looking for. I have four primary sections of my business (A, B, C & D, for example). each section has it's own page each section also ha

  • How can I query data from a linked server, and pass it parameters to filter by? 2013-05-06

    I have a really big query that needs to be run on multiple databases, and the results appended to a temp table and returned. The basic syntax looks something like this: INSERT INTO #tmpTable (Id, ...) SELECT T1.Id, ... FROM Server.Database.dbo.Table1

  • How can I query contact from lead conversion to update account field? 2015-02-13

    The situation is that I want to update a lead field that is map with contact field over a field in the account. I have tried a trigger in the account after insert and query the child on the contact but is not working. Any ideas? Thanks! -------------

  • How can I redirect user from any error 403 to a custom page using .htaccess? 2016-07-05

    So far I've found that ErrorDocument 403 / should be added to root .htaccess, but for some reason it doesn't seem to work. All help highly appreciated.

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 6.992 (s). 13 q(s)