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

Viewing 9 results - 61 through 69 (of 69 total)
  • Author
    Search Results
  • #52218

    In reply to: Getting value from url


    Anonymous
    Inactive

    Well, that breaks the code, the part where the echo should be doens’t show anymore. The rest doesn’t show neither.

    <?php global $searchandfilter;
    $sf_current_query = $searchandfilter->get(15)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['name'] . '</div>';
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    } ?>
    #52114

    In reply to: Getting value from url


    Trevor
    Participant

    What does this give?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['name'] . '</div>';
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }
    #51898

    In reply to: Getting value from url


    Anonymous
    Inactive

    Hi Trevor, I got it to work.
    Using this code:

    function refresh() {
    		$('.things').load(document.URL +  ' .things');
    	}
    	//detects the start of an ajax request being made
    		$(document).on("sf:ajaxstart", ".searchandfilter", function(){
    		  console.log("ajax start");
    
    		});
    
    		//detects when the ajax request has finished and the content has been updated
    		// - add scripts that apply to your results here
    
    		$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
    			console.log("ajax complete");
    			//so load your lightbox or JS scripts here again
    			refresh();
    		});
    
    		//an event fired when S&F is initialised and S&F scripts have been loaded
    		$(document).on("sf:init", ".searchandfilter", function(){
    			console.log("S&F JS initialised");
    		});

    The only thing is, it posts the whole category and name: Aantal personen: 20 of meer personen. You’ve already tackelled this problem here: https://support.searchandfilter.com/forums/topic/how-to-style-the-search-data/

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }

    Which would display “20 of meer personen” but What I would like is to have it show “Aantal personen:<br />20 of meer personen.

    What to do?

    #46959

    Trevor
    Participant

    OK

    I have re-written that a bit and added a new line after each line output. It may not work, but it is better code:

    <?php
      global $searchandfilter;
      $sf_current_query = $searchandfilter->get(2327)->current_query()->get_array();
      if (isset ($sf_current_query)) {
        foreach($sf_current_query as $key) {
          echo '<span class="results-term">' . $key['active_terms'][0]['name'] . '</span><br />';
        }
      }
    ?>
    #43915

    Trevor
    Participant

    Ok.

    So, this is the code I made:

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query()->get_array();
    foreach($sf_current_query as $key) {
      echo '<div>' . $key['active_terms'][0]['name'] . '</div>';
    }

    If you wanted to put the X before each, replace the echo line with something like this:

    echo '<div><a id="executeMyCodeLink" href="#">X</a> ' . $key['active_terms'][0]['value'] . '</div>';
    

    Where the code to add to the page would be something like this

    <script>
      $('#executeMyCodeLink').click(function(event) {
        /// Your code here
      });
    </script>

    But that is beyond the scope of what I can do easily 🙁

    #35604

    Ross
    Keymaster

    what happens if you var_dump the array:

    <?php
    //Get a single fields values using labels
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(147)->current_query();
    var_dump($sf_current_query->get_array());
    ?>

    CAn you paste the output here?

    Thanks

    #31935

    Anonymous
    Inactive

    So I’ve been trying to pull the field name from the Active Query Object, but I’m not able to pull any of custom fields, just categories.

    I’m able to get _sft_credit_card_category, but not the post_meta fields of _sfm_issuer and _sfm_credit_quality.

    
    <?php
    //grab the active query from our search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(615)->current_query();
    var_dump($sf_current_query->get_array());
    
    echo $sf_current_query->get_field_string("_sft_credit_card_category");
    echo $sf_current_query->get_field_string("_sfm_issuer");
    echo $sf_current_query->get_field_string("_sfm_credit_quality");
    ?>
    
    #30635

    Anonymous
    Inactive

    Hey Ross,

    Did you try it on the results.php located in the avada theme folder /search-filter ?

    I tried this again with the following two codes;

    <?php
    //Get an array of objects containing data for the current search/filter
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(14458)->current_query();
    var_dump($sf_current_query->get_array());
    ?>

    and

    <?php
    //Get a single fields values using labels
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(14458)->current_query();
    echo $sf_current_query->get_field_string(“_sft_category”);

    ?>

    Neither are able to pull the values I need.

    I’d like to turn the Categories In: line to not be bulleted and be on the same line. If I can pull the category then it would be fine.

    I tried the above codes at the top of the results.php and neither worked.

    Any idea why ?

    #26959

    Anonymous
    Inactive

    Just an update.
    I tried to use following code but it seems that a function does not exists:

    <?php
    //Get an array of objects containing data for the current search/filter
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1526)->current_query();
    var_dump($sf_current_query->get_array());
    ?>

    ERROR: Fatal error: Call to a member function get() on a non-object in …

Viewing 9 results - 61 through 69 (of 69 total)