Title: Create a query
Last modified: August 18, 2016

---

# Create a query

 *  [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/)
 * Hi i want to create a query that displays all the contents of cat_ID whose value
   is 4. I mean the wp_posts table whose cat_ID in the table wp_categories is 4.
   How to do that?

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

 *  [tsguitar](https://wordpress.org/support/users/tsguitar/)
 * (@tsguitar)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598201)
 * You mean you only want to display posts from category 4? Directly from the [Codex page](http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters):
   `
   <?php query_posts('cat=4'); ?>`
 *  Thread Starter [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598205)
 * Yes, I want to create a code that will display all the value 4 of cat_id in the
   wp_categories table and I want to post only the TITLE and DATE only on my homepage.
   How to do that?
 *  [tsguitar](https://wordpress.org/support/users/tsguitar/)
 * (@tsguitar)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598240)
 * So, on your home page, you only want to list content from category 4? Put this
   in place of your current Loop:
 *     ```
       <?php query_posts('cat=4');
       if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <p><a href="<?php the_permalink() ?>" rel="bookmark" title="permalink to <?php the_title(); ?>"><?php the_title(); ?></a></p>
       <p><?php the_time('d, M, Y') ?></p>
       <?php endwhile; else: ?>
       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
       <?php endif; ?>
       ```
   
 *  Thread Starter [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598310)
 * Thank you very much. It is a great help. One thing question is. Is this should
   work in my website homepage? Actually my blogs are located in [http://www.mydomain.com/blogs](http://www.mydomain.com/blogs).
   And I want to display this information to [http://www.mydomain.com](http://www.mydomain.com)
   only. Is there any code that I have to call to the blogs folder? Thanks in advance.
 *  Thread Starter [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598333)
 * Please help. Thanks.
 *  [tsguitar](https://wordpress.org/support/users/tsguitar/)
 * (@tsguitar)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598346)
 * First off, does that query do what you need it to?
 * Secondly, you can include WordPress content on any page that you add the following
   to the top of:
 *     ```
       <?php
       /* Short and sweet */
       require('path/to/wp-blog-header.php');
       ?>
       ```
   
 * [http://wordpress.org/support/topic/127103?replies=15#post-592826](http://wordpress.org/support/topic/127103?replies=15#post-592826)
 *  Thread Starter [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598353)
 * One last question, I am not sure where is that **current Loop** located? Is that
   a file you mentioned (wp-blog-header.php)? I am not sure where to put the code
   below. Thanks and sorry, this is my first to used WordPress.
 *     ```
       <?php query_posts('cat=4');
       if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <p><a href="<?php the_permalink() ?>" rel="bookmark" title="permalink to <?php the_title(); ?>"><?php the_title(); ?></a></p>
       <p><?php the_time('d, M, Y') ?></p>
       <?php endwhile; else: ?>
       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
       <?php endif; ?>
       ```
   
 *  [tsguitar](https://wordpress.org/support/users/tsguitar/)
 * (@tsguitar)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598374)
 * The Codex is a good resource:
    [http://codex.wordpress.org/The_Loop](http://codex.wordpress.org/The_Loop)
   specifically: [http://codex.wordpress.org/The_Loop#WordPress_1.5](http://codex.wordpress.org/The_Loop#WordPress_1.5)
 *  Thread Starter [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598399)
 * Thanks tsguitar.. It really works… I learned a lot of this template tags.
 * Now, I have another question. This is in connection with the problem above. The
   template tags above shows I have 25 titles with dates. Now, I want to display
   only 4 titles with dates then there is an option that click here for the next
   four titles with dates. How will I do that?
 * This should fixed my problem.
 * Thanks
 *  Thread Starter [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598401)
 * That’s the last problem 🙂
 *  [Sivar](https://wordpress.org/support/users/sivar/)
 * (@sivar)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598402)
 * Modify `query_posts('cat=4');` to `query_posts('cat=4&showposts=4');`. See [query_posts() in the codex](http://codex.wordpress.org/Template_Tags/query_posts)
   for more options.
 *  Thread Starter [dudskie](https://wordpress.org/support/users/dudskie/)
 * (@dudskie)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598403)
 * I mean the second four will show if I click Next, then when I click Previous 
   it will go to the previous post. Sorry for misunderstanding. 🙂

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

The topic ‘Create a query’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 12 replies
 * 3 participants
 * Last reply from: [dudskie](https://wordpress.org/support/users/dudskie/)
 * Last activity: [18 years, 8 months ago](https://wordpress.org/support/topic/create-a-query/#post-598403)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
