Forums Forums Search Search Results for 'current_query() get_array'

Viewing 10 results - 41 through 50 (of 69 total)
  • Author
    Search Results
  • #141086

    In reply to: Some Ui questions


    Anonymous
    Inactive

    ok, great help over skype Trevor – exactly what i was after and pretty much all sorted – thanks!

    for anyone interested

    1. use pre and print r instead of var dump to get the bits you need:

    $sf_current_query = $searchandfilter->get(7050)->current_query();
    	echo '<pre>'; 
    	print_r($sf_current_query->get_array());
    	echo '</pre>';

    2. I ended up with this in my page template to target the ACF meta name chosen in the S&F query – i also ended up trying to cope with the All values parts being sent if no specific options are selected (i hide all items selection in front end):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(7050)->current_query()->get_array();
    
    if ($sf_current_query['_sfm_comfort']['active_terms'][0]['name'] == ""){
      echo 'no preference for comfort';
    } else {
      echo '$sf_current_query['_sfm_comfort']['active_terms'][0]['name'] . ' comfort';
    }
    #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.

Viewing 10 results - 41 through 50 (of 69 total)