Title: WordPress Post Query
Last modified: August 19, 2016

---

# WordPress Post Query

 *  [Ali Hussain](https://wordpress.org/support/users/b4db0y/)
 * (@b4db0y)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/wordpress-post-query/)
 * I wanted to know if there was a query or one could create a query like
 * if is category and if sticky display the post else do nothing?
 * Thanks

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [raskull](https://wordpress.org/support/users/raskull/)
 * (@raskull)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613398)
 * Maybe there’s something here for you: [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)?
 *  Thread Starter [Ali Hussain](https://wordpress.org/support/users/b4db0y/)
 * (@b4db0y)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613425)
 * I tried that, but am not able to get it to work.
 *  [raskull](https://wordpress.org/support/users/raskull/)
 * (@raskull)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613453)
 *     ```
       <?php
       //return sticky posts in categories 3 and 7
       query_posts(array(
       	'post__in'=>get_option('sticky_posts'),
       	'cat'=>'3,7'
       	));
       if (have_posts()) : while (have_posts()) : the_post();
       ?>
       ```
   
 *  Thread Starter [Ali Hussain](https://wordpress.org/support/users/b4db0y/)
 * (@b4db0y)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613457)
 * thanks raskull.
    I edited some parts
 *     ```
       <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       $sticky=get_option('sticky_posts');
       $args=array(
       'cat'=>232,
       'caller_get_posts'=>1,
       'post__in' => $sticky,
       'paged'=>$paged,
       );
       query_posts($args); while ( have_posts() ) : the_post()  ?>
       ```
   
 * Wanted to know, isn’t there any way for the cat number to autofill, like if the
   user in on the autos category it is filled as autos
 *  [raskull](https://wordpress.org/support/users/raskull/)
 * (@raskull)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613466)
 * Tell me more about how/where you plan to use this…
 *  Thread Starter [Ali Hussain](https://wordpress.org/support/users/b4db0y/)
 * (@b4db0y)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613467)
 * i will be having a classified theme (study related)
 * where there be categories like
    – ACCA – O Levels – A Levels – Matriculate – 
   Intermediate etc.
 * If the user visits acca, the sticky posts of ACCA be shown.
    If he visits o levls,
   the sticky from that category is posted. and so on.
 * Again thankyou
 *  [raskull](https://wordpress.org/support/users/raskull/)
 * (@raskull)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613468)
 * Do you have a file named category.php? That might go a long way towards what 
   you’re looking for. It’s what results if you click a category link (if you have
   category.php, otherwise it moves on to archive.php). Take a look in archive.php
   to see what’s going on — you only need the part related to category to put in
   your category.php file.
 * [http://codex.wordpress.org/Template_Hierarchy](https://wordpress.org/support/topic/wordpress-post-query/?output_format=md)
   
   [http://codex.wordpress.org/Category_Templates](https://wordpress.org/support/topic/wordpress-post-query/?output_format=md)
 * My point is — category.php already knows what category to display because it 
   came from a category link. Let me know if that doesn’t help!
 *  Thread Starter [Ali Hussain](https://wordpress.org/support/users/b4db0y/)
 * (@b4db0y)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613482)
 * got it working …thankz

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘WordPress Post Query’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 8 replies
 * 2 participants
 * Last reply from: [Ali Hussain](https://wordpress.org/support/users/b4db0y/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/wordpress-post-query/#post-1613482)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
