Search Results for 'sf_current_query get_array'

Forums › Forums › Search › Search Results for 'sf_current_query get_array'

Viewing 10 results – 71 through 80 (of 103 total)
  • Author
    Search Results
  • #131197

    Trevor
    Participant

    The first thing then is to find what the array (data) looks like after you submit a search (with values in those two fields). Into whichever results template you are using, I need you to add this PHP code (before the loop runs), and it will print out the array of data to your screen, which you can then post back here within code ticks (the backwards quote mark that is on the key normally to the left of the main keyboard ‘1’ key, one before the code and one after it):

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(12345)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query,true),'</pre>';
    ?>

    Where I have used 12345, you need to replace that for the ID of your form.


    Anonymous
    Inactive

    Hi Trevor,

    Thanks for the reply, I found the solution:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1274)->current_query()->get_array();
    foreach($sf_current_query as $key) {
    	echo '<span>' . $key['value'] . ' ' . $key['name'] . ' ' . $key['active_terms'][0]['name'] . ', </span>'; 
    	}	
    #122348

    In reply to: Category Description


    Trevor
    Participant

    Can you use this code to print out the query:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(119)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query),'</pre>';
    ?>
    #122346

    Trevor
    Participant

    The first thing to do is to be able to print to your page the current query (which is an array), and do a few searches to see what the data looks like, when the category is set, and when it is set to ALL. You would do this using the PHP print_r function, so a quick search for snippets on this forum later …

    See if this prints your query out:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(2051)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query),'</pre>';
    ?>
    #122324

    In reply to: Category Description


    Anonymous
    Inactive

    Okay I’ve worked out how to obtain the ID and get the description but the ID has an extra 1 at the end of the string which I’ve had to strip off.

    Can you see why it would have the extra one and how to avoid it?

    Thanks

    		<?php global $searchandfilter;
    			$sf_current_query = $searchandfilter->get(119)->current_query()->get_array();
    			$currentCat = $sf_current_query['_sft_project_category']['active_terms'][0]['id'];
    			$currentCatID = rtrim($currentCat,'1');
    			echo category_description( $currentCatID );
    		 ?>
    #108703

    Anonymous
    Inactive

    GOT IT!!!

    global $searchandfilter;
    
     $sf_current_query = $searchandfilter->get(504)->current_query()->get_array();
    
     if (empty($sf_current_query)) {
        echo ('All Articles');
        }
     else {
       echo $sf_current_query['_sft_category']['active_terms'][0]['name'];
     }

    The above code worked like a charm, I also use the “Archive” setting as you suggested! Thanks so much for your help on this one!! Finally working properly!! 🙂

    #108628

    Anonymous
    Inactive

    Hi Trevor,

    UPDATE! I’ve managed to half get it working!!!

    It now works for all categories except the “All Categories” one, this seems to behave differently to the others and the code I have used doesn’t bring it in:

    $sf_current_query = $searchandfilter->get(766)->current_query()->get_array();
     echo $sf_current_query['_sft_category']['active_terms'][0]['name'];

    I’ve left the printr statement in on the live site so you can get a picture of what is happening. I presume there may need to be an if statement added but I have yet to be able to pull in the “All categories” heading… I was however thinking of just hard coding a title in as it is only one title?? But i’m not sure how I would do it. I’m sure there is a “proper” fix to this though?

    I hope you have a good weekend

    #108514

    Trevor
    Participant

    You tried this?

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(504)->current_query()->get_array();
    echo '<pre>',print_r($sf_current_query),'</pre>';
    ?>
    #108481

    Trevor
    Participant

    Ah, I see the erro. Not sure how many steps back you will need to take though.

    $sf_current_query = $searchandfilter->get(504)->current_query()->get_array();
    

    And look at what is in THAT array using print_r.

    #104843

    Anonymous
    Inactive

    I have two forms that I’d like to work together. The search form sits in the header and is only a search input (sfid 5729). The Filter form sits in the sidebar and has dropdowns for 3 custom taxonomies plus a from and to date (sfid 5727). They both are set to display in archive.php. The search form will use a url such as this, https://boardofednew.webdev.idaho.gov/search/?_sf_s=test.

    The archive.php sidebar is implemented with content aware sidebars plugin and the sf widget for this filter form is set to display in it (5727).

    So when I access the current press releases from the menu using url https://domainnamehere/resources/?_sft_resourcetype=press-releases and archive.php the filter form (5727) displays properly along with the filtered results for press releases. However, when I use the search form from the header (5729), it displays search results properly using archive.php, but it does not display the filter form (5757) in the sidebar. My intent is to return the search results for the term, then filter it further with the form in the sidebar. Code for archive.php follows:

    ‘
    <?php
    /**
    *
    * Description: Generic Index Page
    *
    * Used to display archive-type pages if nothing more specific matches a query.
    * For example, puts together date-based pages if no date.php file exists.
    *
    * If you’d like to further customize these archive views, you may create a
    * new template file for each one. For example, tag.php (Tag archives),
    * category.php (Category archives), author.php (Author archives), etc.
    *
    * @link https://codex.wordpress.org/Template_Hierarchy
    *
    * @package FoundationPress
    * @since FoundationPress 1.0.0
    */
    ?>
    <?php get_header(); ?>

    <main id=”main” class=”body-content row column” role=”main”>
    <?php get_template_part(‘template-parts/breadcrumbs’); ?>
    <div class=”medium-8 columns”>
    <header class=”page-header”>
    <?php
    global $searchandfilter;
    $sf_current_query_1 = $searchandfilter->get(5279)->current_query(); // 5279 is search input only
    $search_term = $sf_current_query_1->get_search_term();
    $sf_current_query_2 = $searchandfilter->get(5277)->current_query(); // 5277 is custom taxonomy filter input only
    $sarr = $sf_current_query_2->get_array();
    $fromDate = $sarr[_sf_post_date][active_terms][0][value] ;
    $toDate = $sarr[_sf_post_date][active_terms][1][value];
    $type = $sf_current_query_2->get_field_string(“_sft_resourcetype”);
    if ($type) {
    $type = substr($type, strpos($type, “:”) + 1);
    }
    $topic = $sf_current_query_2->get_field_string(“_sft_primarytopic”);
    if ($topic) {
    $topic = substr($topic, strpos($topic, “:”) + 1);
    }
    $audience = $sf_current_query_2->get_field_string(“_sft_audience”);
    if ($audience) {
    $audience = substr($audience, strpos($audience, “:”) + 1);
    }
    if ($search_term) {
    $type = “Search Results”;
    }
    echo ‘<h1>’ . $type . ‘</h1>’;
    echo ‘<h2 class=”subheader”>’ . $topic . ” / “. $audience . ‘</h2>’;
    echo ‘<p class=”small”>Note: Select date range or change resource, topic or audience as needed.</p>’;
    ?>
    </header><!– .page-header –>
    <?php if (have_posts()) : ?>
    <section <?php post_class(); ?> >
    <?php while (have_posts()) : the_post(); ?>
    <?php get_template_part( ‘template-parts/content’, get_post_format() ); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php get_template_part( ‘template-parts/content’, ‘none’ ); ?>
    </section>
    <?php endif; // End have_posts() check. ?>
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if ( function_exists( ‘foundationpress_pagination’ ) ) { foundationpress_pagination(); } else if ( is_paged() ) { ?>
    <nav id=”post-nav”>
    <div class=”post-previous”><?php next_posts_link( __( ‘← Older posts’, ‘foundationpress’ ) ); ?></div>
    <div class=”post-next”><?php previous_posts_link( __( ‘Newer posts →’, ‘foundationpress’ ) ); ?></div>
    </nav>
    <?php } ?>
    </div>
    <?php get_sidebar(); ?>
    </main>
    <?php get_footer(); ?>
    ‘

Viewing 10 results – 71 through 80 (of 103 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.