Forums Forums Search & Filter Pro "Showing results under X and Y and Z"

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

    Hello,

    Just a quick question on where to get started to display a heading sentence before displaying the results, inside search.php, so that it states something like_

    Displaying results under CATEGORY-1 and META-1 and TAG-1

    Should I parse the url, then get the category slug, then query to get the category name?

    Ross Moderator
    #14688

    Hey Marc

    You’ve got the right idea.

    Depends on where you are needing to do it, but you could check the $wp_query->query object, which will have those vars from the URL.

    Just to note, S&F adds a prefix of _sft_ to taxonomies and _sfm_ for meta fields which you may need to strip before processing.

    Here is a similar post where I’ve written a function for parsing taxonomies to get you started:

    https://support.searchandfilter.com/forums/topic/how-to-show-cats-title-in-search-result/

    ๐Ÿ™‚

    Anonymous
    #14966

    Hi Ross,
    Thank you, you showed me the light ๐Ÿ˜‰
    Here is my approach (I am using the Advanced Custom Fields plugin for meta values):

    
    <?php 
              $copy = array();
              $is_search = false;
      	  $search_query = $wp_query->query;
    
              // META
              if($search_query['_sfm_location']){
                $field = get_field_object('location', false, array('load_value' => false));
                foreach ($field['choices'] as $key => $value) {
                  if($key == $search_query['_sfm_location']){
                    $copy[] = $value;
                  }
                }
                $is_search = true;
              } 
    
              // TAXONOMY
              if($search_query['_sft_project_category']){
                $term = get_term_by('slug', $search_query['_sft_project_category'], 'project_category');
                $copy[] = $term->name;
                $is_search = true;
              }
      ?>
    
    <?php if($is_search): ?>
      <p>Searching filters for: <?php echo implode(', ', $copy); ?></p>
    <?php else: ?>
      <p>A simple copy when if no search.</p>
    <?php endif; ?>
    
    Ross Moderator
    #15004

    Thanks for that!

    Does that grab the names of the values from ACF automatically?

    Anonymous
    #15035

    Yes!
    get_fields() and get_field_object() does grab all custom fields info
    http://www.advancedcustomfields.com/resources/get_fields/

    Ross Moderator
    #15036

    Ohhh lovely! Hadn’t got round to checking ACF functions yet but they’ll help with grabbing the names automatically in some updates I’m working on ๐Ÿ˜‰

    Anonymous
    #21700

    Hi Ross,

    I am back on this topic.
    I created a dropdown field with your form, then filled it with some options.

    Now i want to retrieve those options to match them to $wp_query->query and display the proper heading statement.

    Thanks!

    Ross Moderator
    #21816

    Hey Marc,

    Not sure I follow, the code you placed above is what I think you mean, but then that must mean I’m getting confused…!

    If you can please elaborate a little more? ๐Ÿ™‚

    Thanks

    Anonymous
    #21823

    Sorry, i was too straightforward. I put it another way:

    Imagine I create a new form. Create a new field, type Post Meta. Then i choose to Display my Meta Field with a dropdown, which I manually fill it some options: value_1, label_1, .... value_n, label_n. Done.

    Whan I submit the form and go to a new page, i will e able to retrieve the value_n via wp_query, but then how can I get the corresponding label_n

    Thank you!

    Ross Moderator
    #22167

    Hey Marc

    I thought thats what you were explaining all the way at the top.

    S&F doesn’t have a way to get this info, for example, if it was a taxonomy you would use – https://codex.wordpress.org/Function_Reference/get_term_by against the value.

    I just did a quick google and found this:

    http://wordpress.stackexchange.com/a/140825/37783 – check step 3 of this answer RE label – I guess this is an ACF question really.

    Thanks

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