Title: Custom Query PHP Loop Problem
Last modified: August 20, 2016

---

# Custom Query PHP Loop Problem

 *  Resolved [LordDoig](https://wordpress.org/support/users/lorddoig/)
 * (@lorddoig)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/custom-query-php-loop-problem/)
 * Hello,
 * I have created a function that returns a specific authors 5 most popular posts(
   reading the popularity data directly from the DB as recorded by the Top 10 plugin).
   Previously I was having an excerpt created by truncating the post content however
   I need to alter this to only do this if an excerpt isn’t set. After modifying
   the code to what you see below, it shows an excerpt if the length of post_excerpt
   is greater than 6 characters but if not it shows the same excerpt (which seems
   to be coming from one of the posts that isn’t even in the result set) for every
   other result. I’m usually quite good at troubleshooting this kind of thing but
   I’ve hit a wall with this.
 * The code:
 * _[code moderated per forum rules - please follow [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)]_
 * The fact this is returning an excerpt that isn't even in the result set (incidentally
   it's 'Hello!') is making me think it's a duplication of variables from somewhere
   else in my function/plugin structure but for the life of me I can't find it. 
   I have also tried prefixing all of the common-looking variables with mp_ in an
   attempt to sort this - no luck!
 * I'd be grateful for any help.
 * Thanks,
 * Sean

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

 *  Thread Starter [LordDoig](https://wordpress.org/support/users/lorddoig/)
 * (@lorddoig)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/custom-query-php-loop-problem/#post-2243358)
 * Apologies for the excessive code – as you can see I’m new to this board.
 * The code is now at [http://pastebin.com/94TUE3br](http://pastebin.com/94TUE3br).
 *  Thread Starter [LordDoig](https://wordpress.org/support/users/lorddoig/)
 * (@lorddoig)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/custom-query-php-loop-problem/#post-2243362)
 * Fixed. One missing comma in the query. How stupid.

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

The topic ‘Custom Query PHP Loop Problem’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 1 participant
 * Last reply from: [LordDoig](https://wordpress.org/support/users/lorddoig/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/custom-query-php-loop-problem/#post-2243362)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
