• Resolved yann1ck

    (@ja4st3r)


    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 the cf7sg_dynamic_select_post_query hook as well.

    I am using version 4.12.13, not the beta you provided last week because of the textarea bug.

    Kind regards
    Yannick

    • This topic was modified 4 years, 2 months ago by yann1ck.
    • This topic was modified 4 years, 2 months ago by yann1ck. Reason: Code styling was broken
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    Hello Yannick

    let me check and revert back.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    hey there, sorry for the delay in my reply, have been very busy at work.

    So checked this, and realised that in the v4 rewrite of the dynamic field module, I changed the names of the filters and deprecated the old ones. However, when I updated the filter helper I made a mistake. So the helper code you copied was simply wrong.

    I have fixed this in v4.13. You can upgrade manually to v4.13.0 RC1 from the GitHub repo or wait till I release the new version.

    Thread Starter yann1ck

    (@ja4st3r)

    Hi Aurovrata,

    thank you very much for looking into the issue and fixing the helper code!

    I will wait for the v4.13 release on wordpress.org and try the new helper function 🙂

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

The topic ‘Query arguments hook not working’ is closed to new replies.