Title: hide draft / unpublished posts from query
Last modified: December 5, 2018

---

# hide draft / unpublished posts from query

 *  Resolved [wasifh](https://wordpress.org/support/users/wasifh/)
 * (@wasifh)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/hide-draft-unpublished-posts-from-query/)
 * I am looking for a solution to hide draft / private posts from displaying under
   current research studies on the link provided. Is there a way to exclude draft
   and private posts from a query for relationship fields.
 * Preference would be not to touch the plugin’s code because it’ll be overridden
   if I update it later on. Can i add a function in my own code (e.g., in my functions.
   php) to achieve the same result?
    -  This topic was modified 7 years, 5 months ago by [wasifh](https://wordpress.org/support/users/wasifh/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhide-draft-unpublished-posts-from-query%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [Frederik Rosendahl-Kaa](https://wordpress.org/support/users/frederik-rosendahl-kaa/)
 * (@frederik-rosendahl-kaa)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/hide-draft-unpublished-posts-from-query/#post-10950227)
 * Hi [@wasifh](https://wordpress.org/support/users/wasifh/),
 * This should be possible using the built-in filter hooks in the plugin.
 * I have done an example function that only shows the posts that have been published
   using this filter hook function acfvc_relationship.
 * [https://gist.github.com/frederikrosendahlkaa/2ad88c625db4ea1582f29af2dfc288f7](https://gist.github.com/frederikrosendahlkaa/2ad88c625db4ea1582f29af2dfc288f7)
 * All you have to do is insert it into function.php in the theme / child theme 
   folder and make sure the relationship field is set to return format Post Object.
   
   If it is not set to return format Post Object then code must be changed so that
   it can use return format Post ID.
 * Best regards
    Frederik Rosendahl-Kaa
 *  Thread Starter [wasifh](https://wordpress.org/support/users/wasifh/)
 * (@wasifh)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/hide-draft-unpublished-posts-from-query/#post-10950663)
 * Awesome, thank you so much for your help. Adding the code in fuction.php did 
   the trick

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

The topic ‘hide draft / unpublished posts from query’ is closed to new replies.

 * ![](https://ps.w.org/acf-vc-integrator/assets/icon-128x128.png?rev=1450656)
 * [ACF-VC Integrator](https://wordpress.org/plugins/acf-vc-integrator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-vc-integrator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-vc-integrator/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-vc-integrator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-vc-integrator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-vc-integrator/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [wasifh](https://wordpress.org/support/users/wasifh/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/hide-draft-unpublished-posts-from-query/#post-10950663)
 * Status: resolved