Query arguments hook not working
-
Hi Aurovrata,
I using a dynamic dropdown to show a list of posts, but I want to show draft posts as well. So I wanted to hook in the query using the provided filter:
add_filter( 'cf7sg_dynamic_select_post_query','test_dynamic_list',10,3); /** * Filter post query for dynamic dropdown options. * @param array $args an arra of query terms. * @param WPCF7_FormTag $tag the field being populated. * @param string $cf7_key the form unique key. * @return array an arra of query terms. */ function test_dynamic_list($query_args, $tag, $cf7_key){ //if you have a dynamic dropdown field with posts as list source. //$query_args array to filter query arguments used to populate dynamic dropdown of posts. //these arguments are passed to the function get_posts($query_args). (codex: https://codex.wordpress.org/Template_Tags/get_posts) if('test'!==$cf7_key || 'test-dropdown' !== $tag->name){ return $query_args; } //setup your custom query... return $query_args; }But it is not working for me. I tried to add
$query_args['post_status'] = 'any';, I also tried to limit the numberofposts or just return null to break the query. Changing the priority has no effect as well.I at a look at the code and found the deprecated hook
cf7sg_dynamic_dropdown_post_query(github), which works perfectly fine. So perhaps there is some issue with the new hook?At least for the hook I am using it should just be
$tag, not$tag->name. Not sure if thats true for thecf7sg_dynamic_select_post_queryhook as well.I am using version 4.12.13, not the beta you provided last week because of the textarea bug.
Kind regards
Yannick
The topic ‘Query arguments hook not working’ is closed to new replies.