Title: Custom Post Query
Last modified: August 19, 2016

---

# Custom Post Query

 *  Resolved [Chris Sanders](https://wordpress.org/support/users/csand10045/)
 * (@csand10045)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/custom-post-query/)
 * I need to sort a custom post type named ‘news’ posts based on a meta_key named“
   DatePublished”. In mysql, the query works correctly, but I can’t get the code
   to go through the loop and echo the posts. The code is below:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * Help is greatly appreciated.

Viewing 1 replies (of 1 total)

 *  Thread Starter [Chris Sanders](https://wordpress.org/support/users/csand10045/)
 * (@csand10045)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/custom-post-query/#post-1992848)
 * This one was too easy. I changed how things are done a little bit, but the biggest
   problem was the lack of spaces at the end of lines within the query…dumb mistake.
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_

Viewing 1 replies (of 1 total)

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

## Tags

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

 * 1 reply
 * 1 participant
 * Last reply from: [Chris Sanders](https://wordpress.org/support/users/csand10045/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/custom-post-query/#post-1992848)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
