Title: Duplicate posts from custom loop within a function
Last modified: August 19, 2016

---

# Duplicate posts from custom loop within a function

 *  Resolved [ivyowl](https://wordpress.org/support/users/ivyowl/)
 * (@ivyowl)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-from-custom-loop-within-a-function/)
 * Hi all,
 * Just wondering if anyone could shed some light on this.
 * I’m using a function created to be used with shortcode,
 * it pulls data from custom posts type event within the category specified.
 * I’m getting the data back how i want it but just too many,
 * 4 of 1, 5 of another and 4 again duplicate results from the 3 posts i’m testing
   with.
 * I’ve got some text on a page, with the shortcode below it.
 * using this loop to call it all:
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php the_content()?>
       <?php endwhile; endif; ?>
       ```
   
 * The function code’s here:
 * [http://pastebin.com/maxfQ9Df](http://pastebin.com/maxfQ9Df)
 * and its based on a tutorial by Noel Tock [here](http://www.noeltock.com/web-design/wordpress/how-to-custom-post-types-for-events-pt-2/)
 * Any ideas?
 * Many thanks for any advice.

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-from-custom-loop-within-a-function/#post-1968869)
 * Really difficult to tell without seeing all the code and the output, but the 
   line below seems odd to me because the postmeta table is named in the FROM clause
   and here. Try taking it out of the function.
 * `LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)`
 *  Thread Starter [ivyowl](https://wordpress.org/support/users/ivyowl/)
 * (@ivyowl)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-from-custom-loop-within-a-function/#post-1968939)
 * worked a treat,
 * many thanks

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

The topic ‘Duplicate posts from custom loop within a function’ is closed to new 
replies.

## Tags

 * [duplicate posts](https://wordpress.org/support/topic-tag/duplicate-posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [ivyowl](https://wordpress.org/support/users/ivyowl/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/duplicate-posts-from-custom-loop-within-a-function/#post-1968939)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
