Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search Search Results for 'current_query'

Viewing 10 results - 351 through 360 (of 374 total)
  • Author
    Search Results
  • #42786

    Juan Pablo Gomez
    Participant

    Thanks Trevor!
    I am using a theme I started from underscores template

    Installed the results.php template and I am trying to use the github code here as reference.
    but no luck yet..

    Any chance you can guide me a bit further?

    Where do I place the following code in my results.php if it needs to be before the “have_posts” loop?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();
    echo $sf_current_query->is_filtered();
    #41773

    Adam Wolff
    Participant
    This reply has been marked as private.
    #41768

    Ross
    Keymaster

    Hi Adam

    S&F doesn’t search tag names, nor does the default WP search – try your “Flowers” test with the old search and you will see (you can search tag names by combining S&F with Relevanssi).

    RE the input box, thats the last step we missed!

    So, each of the search input fields, that you have changed to be renamed to _sf_s, also has a value attribute.

    <input type="text" placeholder="<?php _e( 'Search', 'squarecode' ); ?>" value="<?php echo $searchresults; ?>" name="_sf_s" id="s" />

    we need to get the S&F search term into this value attribute. I can see in both your header and search templates, that the query is populated with the value from this line:

    <?php $searchresults = get_search_query(); ?>

    So all we need to do is get S&F search query into that variable – from the docs you would replace the code above with –

    <?php
    	//Get the search term
    	//replace <code>4243</code> with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(4243)->current_query();
    	$searchresults = $sf_current_query->get_search_term();
    ?>

    Thanks

    #39703

    anthos
    Participant

    I finally found this solution:

    $sarr = $sf_current_query->get_array();

    $author = $sarr[authors][active_terms][0][name] ;
    $fromDate = $sarr[_sf_post_date][active_terms][0][value] ;
    $toDate = $sarr[_sf_post_date][active_terms][1][value];

    I hope it keeps on working always!

    #39701

    anthos
    Participant

    Hi!
    Sorry for my late reply but I had to complete another project..
    If I do a var_dump I get the following:
    array(2) { [“authors”]=> array(5) { [“name”]=> string(7) “Authors” [“singular_name”]=> string(6) “Author” [“all_items_label”]=> string(11) “All Authors” [“type”]=> string(9) “post_type” [“active_terms”]=> array(1) { [0]=> array(3) { [“id”]=> int(39) [“name”]=> string(7) “Agenzie” [“value”]=> string(7) “agenzie” } } } [“_sf_post_date”]=> array(1) { [“active_terms”]=> array(2) { [0]=> array(1) { [“value”]=> string(8) “01032016” } [1]=> array(1) { [“value”]=> string(8) “16032016” } } } }

    In my form I have Authors (in this example value for that is “Agenzie”) and Post Date range fields.
    I am not expert in PHP…can you help me to get the authors and post date range?
    As $sf_current_query->get_field_string(“authors”) does not work.

    Thanks

    #37243

    Stephen Tapp
    Participant

    Hi, How would I display the sort order in a way similar to displaying categories or tags? Here’s the code I’m using, but only _sft_category and _sft_school display on my page.

    $args = array(
    	"str" => '<strong>%1$s</strong>: %2$s',
    	"show_all_if_empty" => false
    	//"field_delim" => '<hr />'
    	
    );
    echo $sf_current_query->get_fields_html(array("_sft_category", "_sft_school", "sort_order"), $args);

    Here’s a link to the test page:
    http://staging.cudenvertoday.org/articles

    Thanks!

    #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

    #34998

    Arek Zielinski
    Participant

    Website is actually offline.

    I just put in page template:
    <?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();
    echo $sf_current_query->get_field_string(“_sfm_xxx”);

    ?>

    and Its echo nothing. I’m using ACF fileds

    #34979

    Arek Zielinski
    Participant

    Im trying something like and its not working

    <?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();
    echo $sf_current_query->get_field_string(“_sfm_xxx”);

    ?>

    Url looks like this:
    http://www.xxx.com/?_sfm_xxx&#8230;

    #34656

    Ross
    Keymaster

    Hi Scott

    To answer your questions:

    1) To get data from the current search you can use:
    http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    So, from that link, the code would be

    <?php
    	//Get the search term
    	//replace '1526' with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1526)->current_query();
    	echo $sf_current_query->get_search_term();
    ?>

    2) Which display method are you using? If you are using archive then it sounds like you have set your template up wrong (a little). This really depends on your theme, so go into your theme and take a look at other template files such as archive.php or search.php.

    Usually you should at least be starting with a get_header() and finishing with a get_footer() – but this is really theme dependent – https://codex.wordpress.org/Include_Tags

    Thanks

Viewing 10 results - 351 through 360 (of 374 total)