WordPress.org

Ready to get started?Download WordPress

Forums

Advance WP Query Search Filter
Exclude results of certain custom field value (6 posts)

  1. Aurélien Denis
    Member
    Posted 9 months ago #

    Hi,

    I'm looking for a way to exclude certains results by filtering them based on custom field value.

    Let say I need to filter results with an empty custom field value or something else.

    I can do this using a pre get post but the conditional tag is_search() doesn't seem to work with AWQSF.

    Any idea?

    http://wordpress.org/plugins/advance-wp-query-search-filter/

  2. TC.K
    Member
    Plugin Author

    Posted 9 months ago #

    You can try set the pre_get_post priority to more than 1000, as the plugin uses priority of 1000

  3. Aurélien Denis
    Member
    Posted 9 months ago #

    Thanks for your reply. If I do this, the request is no more working...

    Here is my piece of code :

    http://pastebin.com/iBwtFEfu

  4. TC.K
    Member
    Plugin Author

    Posted 9 months ago #

    Because the query is overrides by your meta query.
    Another way is add the hidden field into the search form, by using awpqsf_addextra_cmf() hook.

    Eg.

    add_filter('awpqsf_addextra_cmf','hidden_cmf_field','',3);
    function hidden_cmf_field($newcmf, $i,$id){
    $excludekey = '';//your exclude meta field key
    $excludecompare = '2';// 2 is the reference number for "!="
    $excludevalue = '';//the meta value that you need to compare

    echo '<input type="hidden" name="cmf['.$i.'][metakey]" value="'.$excludekey.'">';
    echo '<input type="hidden" name="cmf['.$i.'][compare]" value="'.$excludecompare.'">';
    echo '<input type="hidden" name="cmf['.$i.'][value]" value="$excludevalue">';
    }

  5. Aurélien Denis
    Member
    Posted 9 months ago #

    Ok I did this:

    add_filter('awpqsf_addextra_cmf','hidden_cmf_field','',3);
    function hidden_cmf_field($newcmf, $i,$id){
    $excludekey = 'Photos_0';//your exclude meta field key
    $excludecompare = '2';// 2 is the reference number for "!="
    $excludevalue = '';//the meta value that you need to compare
    
    echo '<input type="hidden" name="cmf['.$i.'][metakey]" value="'.$excludekey.'">';
    echo '<input type="hidden" name="cmf['.$i.'][compare]" value="'.$excludecompare.'">';
    echo '<input type="hidden" name="cmf['.$i.'][value]" value="$excludevalue">';
    }

    But where should I put the form ID?

  6. Aurélien Denis
    Member
    Posted 9 months ago #

    My bad it seems to works fine. The last line was missing quotes ;)

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.