Forums Forums Search & Filter Pro "AND" relationship between the different form field

Viewing 10 posts - 1 through 10 (of 16 total)
  • Anonymous
    #11741

    Hi,
    I have made a form with the following :
    Search for keywords
    Taxonomy for ads (category)
    Post Meta for the price
    Post Meta for the size
    Submit button

    But :
    If I only select a category I obtain as a result all the ads
    If I mix section between the field the results are as a “OR” between the fields but I would like to have a “AND” : for exemple only the ads with “these keywords” AND “this category”.

    Can you help me for a correct setup ?
    Thank you.

    Ross Moderator
    #11748

    Hey Didier

    I don’t think thats possible.

    Basically, we use the WP_Query or pre_get_posts to modify your queries for search – and WordPress does not allow for this kind of granular control.

    What you are able to do is set the relationship between taxonomies, categories and tags – using one setting – “and” or “or”.

    WordPress also allows for setting the relationship between your meta queries (post meta fields), to “and” or “or” – however this is between all your meta queries – this option is not integrated in the plugin but I plan to add it as an option in the admin (I may be able to help with custom code if you need to be able to control this).

    Thanks

    Anonymous
    #11763

    Hi Ross?

    I thank that wasn’t clear as I have mixes to problems in the same post :

    > Pb 1
    I have created a search form with different fields including the catégories that comes from my theme (classified ads).
    When I make a search by selecting only one category I obtain all the ads whatever the category they belong to.

    > Pb 2
    It seems that when I make a search that I have a “OR” between the different fields and I would need a “AND” between all the fields.

    Do you thank you can help me ?
    Thank you.

    Ross Moderator
    #11855

    Hey Didier

    For problem 1 see:

    http://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/#h-bad-template

    For problem 2, look in the settings box, in the “tags, categories and taxonomies” tab, there you will find a relationship option, which you can set to AND or OR.

    Thanks

    Anonymous
    #11880
    This reply has been marked as private.
    Ross Moderator
    #11913

    Hey Didier

    So it looks like that code is not directly in your template file – it is in a template part.

    <?php get_template_part( ‘loop’, ‘ad_listing’ ); ?>

    This means it is pulling this file from another location in your theme.

    You will also have to duplicate this file which will be called something like loop-ad_listing.php, and rename it to loop-ad_listing_sf.php

    Then update the line above to something like:

    <?php get_template_part( ‘loop’, ‘ad_listing_sf’ ); ?>

    After this, we will check out the loop-ad_listing_sf.php – because this is where the query will be 🙂

    PS – the filenames I give above may not be correct for your setup – you will have to find the correct one in your theme that get_template_part is loading – you can see how this function works here – http://codex.wordpress.org/Function_Reference/get_template_part

    Thanks

    Anonymous
    #11923

    Great,

    So at this time I have renamed the search.php to search-filter.php and change the line <?php get_template_part( ‘loop’, ‘ad_listing’ ); ?> to <?php get_template_part( ‘loop’, ‘ad_listing_sf’ ); ?>.
    Then I have duplicated loop-ad_listing.php and renamed it to loop-ad_listing_sf.php.

    So the filenames that you gave me were corrects.

    And as far as I have understand, now I have to modify the following content (I am not sure for the line to be removed) :

    <?php
    /**
    * Main loop for displaying ads
    */
    global $cp_options;
    ?>

    <?php allthemes_before_loop(); ?>

    <?php if ( have_posts() ) : ?>

    <?php while ( have_posts() ) : the_post(); ?>

    <?php allthemes_before_post(); ?>

    <div class=”post-block-out <?php cp_display_style( ‘featured’ ); ?>”>

    <div class=”post-block”>

    <div class=”post-left”>

    <?php if ( $cp_options->ad_images ) cp_ad_loop_thumbnail(); ?>

    </div>

    <div class=”<?php cp_display_style( array( ‘ad_images’, ‘ad_class’ ) ); ?>”>

    <?php allthemes_before_post_title(); ?>

    <h3>“><?php if ( mb_strlen( get_the_title() ) >= 75 ) echo mb_substr( get_the_title(), 0, 75 ).’…’; else the_title(); ?></h3>

    <div class=”clr”></div>

    <?php allthemes_after_post_title(); ?>

    <div class=”clr”></div>

    <?php allthemes_before_post_content(); ?>

    <p class=”post-desc”><?php echo cp_get_content_preview( 160 ); ?></p>

    <?php allthemes_after_post_content(); ?>

    <div class=”clr”></div>

    </div>

    <div class=”clr”></div>

    </div><!– /post-block –>

    </div><!– /post-block-out –>

    <?php allthemes_after_post(); ?>

    <?php endwhile; ?>

    <?php allthemes_after_endwhile(); ?>

    <?php else: ?>

    <?php allthemes_loop_else(); ?>

    <?php endif; ?>

    <?php allthemes_after_loop(); ?>

    <?php wp_reset_query(); ?>

    Anonymous
    #12052

    Hi Ross,

    Do you think you can help me on identifying the line to be removed from the code in loop-ad_listing_sf.php shown in my previous post ?
    For this moment I succeed in having the results with the good page design but there isn’t any filter based on the Taxonomy and Post Meta.

    Thank you.

    Ross Moderator
    #12055

    Hey Didier

    Looks like your theme is wrapping the query up (but at this stage I’m just guessing).

    If we have this line:

    <?php if ( have_posts() ) : ?>

    It means the query has already been performed, and this line is a check to see if there are any resultsc from the query…

    So logically I would guess that a query may be being performed before this, in this function:

    <?php allthemes_before_loop(); ?>

    However this may have more than just the query and removing it may have unexpected results…

    Thanks

    Anonymous
    #12090

    Hi Ross,

    Thanks a lot for your help.
    So as I understand the loop-ad_listing_sf.php is calling the function <?php allthemes_before_loop(); ?>.
    The part to be removed would probably be in this function, right ?

    Your plugin seems to be the best for my needs and I really want to make it works.
    Do you think then I have to look in the allthemes_before_loop function to modify it ?

    Thanks.

Viewing 10 posts - 1 through 10 (of 16 total)