Skip to content

Instantly share code, notes, and snippets.

@natenault
Created January 18, 2018 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natenault/770cf0f833fe2e590e88b1cdf9d9e2ea to your computer and use it in GitHub Desktop.
Save natenault/770cf0f833fe2e590e88b1cdf9d9e2ea to your computer and use it in GitHub Desktop.
/**
* Include only published posts in post query.
*
* @param array $args
* @param array $field
* @param int $post_id
* @return array
*/
function nn_query_only_published_posts( $args, $field, $post_id ) {
$args['post_status'] = array( 'publish' );
return $args;
}
add_filter( 'acf/fields/relationship/query', 'nn_query_only_published_posts', 10, 3 );
add_filter( 'acf/fields/post_object/query', 'nn_query_only_published_posts', 10, 3 );
add_filter( 'acf/fields/page_link/query', 'nn_query_only_published_posts', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment