Forums Forums Search & Filter Pro How to show the currently selected title only

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

    I have managed to get my AJAX form to show the currently selected category title, the only issue is the string also contains “categories:” and “category:” before the title but I only want the actual category name, is there a way to just get the category title without the extraneous words before it please?

    Thanks

    Trevor
    #108282

    What code are you using to get them? You can post code here using back ticks (not quotes) before and after the code; on my keyboard it is the key next to the ‘1’.

    Anonymous
    #108331
    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(504)->current_query();
    echo $sf_current_query->get_field_string("_sft_category");
    ?>

    The above code gets the current category, but how to do it without the extraneous word(s) before it?

    Thanks

    Trevor
    #108367

    You would need to dig deeper in the $sf_current_query array I suspect. You can echo the array to a page with a PHP print_r function inside pre tags.

    Anonymous
    #108431

    Okay, I have used the following code to display the array:

    <?php echo '<pre>',print_r($sf_current_query),'</pre>';?>

    This displays the following:

    Search_Filter_Active_Query Object
    (
        [sfid] => 504
        [is_set:Search_Filter_Active_Query:private] => 1
        [query_array:Search_Filter_Active_Query:private] => Array
            (
            )
    
        [form_fields:Search_Filter_Active_Query:private] => Array
            (
                [_sft_category] => Array
                    (
                        [type] => category
                        [input_type] => radio
                        [heading] => Categories
                        [accessibility_label] => 
                        [all_items_label] => All Articles
                        [show_count] => 1
                        [hide_empty] => 1
                        [hierarchical] => 0
                        [include_children] => 1
                        [drill_down] => 0
                        [sync_include_exclude] => 1
                        [combo_box] => 0
                        [operator] => or
                        [order_by] => default
                        [order_dir] => asc
                        [exclude_ids] => 
                        [taxonomy_name] => category
                    )
    
            )
    

    (plus lots more)

    So what I want is the taxonomy name field but I have no idea how to access this field and echo into my template? Any help here would be much appreciated, I understand this may be out of the scope of support but if it’s something simple that you might know you could really help me out a lot.

    Thanks

    Trevor
    #108444

    If you echo this:

    $sf_current_query['_sft_category']['taxonomy_name']

    What does it give you?

    Anonymous
    #108447
    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(504)->current_query();
    echo $sf_current_query['_sft_category']['taxonomy_name'];
    ?>

    This code gives me an error… although it does look like this should work?

    Trevor
    #108461

    Try this then:

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(504)->current_query();
    echo $sf_current_query['_sft_category'][0]['taxonomy_name'];
    ?>
    Anonymous
    #108464

    Hmm, it’s throwing the same error. In the original snippet there is “->get_field_string” do you think this has something to do with it?

    Trevor
    #108481

    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 posts - 1 through 10 (of 22 total)