Title: API Loop display multiple times (Custom Post type)
Last modified: April 16, 2022

---

# API Loop display multiple times (Custom Post type)

 *  [niel](https://wordpress.org/support/users/nielfernandez/)
 * (@nielfernandez)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/api-loop-display-multiple-times-custom-post-type/)
 * Hi,
 * I am currently working with a custom post type API, and the goal is to fetch 
   the data including the custom post field from API and display on a page using
   shortcode, the problem is when I do that loop the data it will display let say
   I have 4 posts it will display 4 times
 * Posts from backend WordPress ( ref: [https://www.screencast.com/t/HBMLtMSr6se](https://www.screencast.com/t/HBMLtMSr6se))
   
   Title 1 Title 2 Title 3 Title 4
 * // Loop with API (ref: [https://www.screencast.com/t/juquCATM9wv](https://www.screencast.com/t/juquCATM9wv))
   
   Expected Output: Title 1 Title 2 Title 3 Title 4
 * // But the bad result ( ref: [https://www.screencast.com/t/YSCQUIyEu9](https://www.screencast.com/t/YSCQUIyEu9))
   
   Title 1 Title 2 Title 3 Title 4 . Title 1 Title 2 Title 3 Title 4 . Title 1 Title
   2 Title 3 Title 4 . Title 1 Title 2 Title 3 Title 4
    -  This topic was modified 4 years, 1 month ago by [niel](https://wordpress.org/support/users/nielfernandez/).
      Reason: arrange
    -  This topic was modified 4 years, 1 month ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Developing with WordPress
      topic

Viewing 1 replies (of 1 total)

 *  [Steven Lin](https://wordpress.org/support/users/stevenlinx/)
 * (@stevenlinx)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/api-loop-display-multiple-times-custom-post-type/#post-15564927)
 * 1.)
    Are you dealing with Posts or Comments?
 * `get_posts()` is for retrieving Posts, but it seems you’re using it Comments.
   And the arguments you passed in are not listed.
    [https://developer.wordpress.org/reference/functions/get_posts/](https://developer.wordpress.org/reference/functions/get_posts/)
 * 2.)
    Is the order of `return"";` and `endif;` correct?
 * That is, is the code `if(!empty($posts)):` properly closed?

Viewing 1 replies (of 1 total)

The topic ‘API Loop display multiple times (Custom Post type)’ is closed to new 
replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Steven Lin](https://wordpress.org/support/users/stevenlinx/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/api-loop-display-multiple-times-custom-post-type/#post-15564927)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
