Title: Custom Post Query Error
Last modified: May 24, 2021

---

# Custom Post Query Error

 *  [kesking7](https://wordpress.org/support/users/kesking7/)
 * (@kesking7)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/custom-post-query-error/)
 * Hi,
 * I’ve created a query to display custom posts by calling them from the category.
   And the issue is although I want to display 3 different posts in the post section,
   It only displays 1 same post for 3 each content section.
 * Here is the reference screenshot [link ](https://www.linkpicture.com/q/ss_11.png)
   for the issue.
 *     ```
       $args = ( array(
           'category_name'  => 'sidepost',
           'post_status'   => 'publish',
           'posts_per_page' => -1,
       	'order' => 'ASC',
       	'orderby' => 'date',
       ) );
       // the query
       $the_query = new WP_Query( $args ); ?>
   
   
       <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
   
       // CUSTOM PHP & HTML CODE
   
       <?php endwhile; ?>
   
       <?php wp_reset_postdata(); ?>
       ```
   
 * Thanks in advance.
    -  This topic was modified 4 years, 12 months ago by [kesking7](https://wordpress.org/support/users/kesking7/).
    -  This topic was modified 4 years, 12 months ago by [kesking7](https://wordpress.org/support/users/kesking7/).
    -  This topic was modified 4 years, 12 months ago by [kesking7](https://wordpress.org/support/users/kesking7/).

Viewing 1 replies (of 1 total)

 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/custom-post-query-error/#post-14476280)
 * I would use get_posts instead, and a foreach, like this:
 *     ```
       $args = ( array(
           'category_name'  => 'sidepost',
           'post_status'   => 'publish',
           'posts_per_page' => -1,
       	'order' => 'ASC',
       	'orderby' => 'date',
       ) );
       // the query
       $my_posts = get_posts( $args );
       if( ! empty( $my_posts ) ){
       	$output = '<ul>';
       	foreach ( $my_posts as $p ){
       		$output .= '<li><a href="' . get_permalink( $p->ID ) . '">' 
       		. $p->post_title . '</a></li>';
       		$output .= '<li><a href="' . get_permalink( $p->ID ) . '">' 
       		. $p->post_title . '</a></li>';
       	}
       	$output .= '<ul>';
       }
       ```
   
 * You’ll need to modify and add the content based on your requirements, i.e.
    get_the_post_thumbnail()
   the_content()

Viewing 1 replies (of 1 total)

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * Last activity: [4 years, 11 months ago](https://wordpress.org/support/topic/custom-post-query-error/#post-14476280)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
