Forums Forums Search Search Results for 'get_field'

Viewing 10 results - 171 through 180 (of 188 total)
  • Author
    Search Results
  • #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");
    ?>
    
    #31706

    Ross
    Keymaster

    Hi Stephen

    The active query class is not currently too well documented (as its just been created its subject to change a little) but you can certainly change the output of this field.

    Please take a look at this example:

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

    You can see str variable is the format output of html for each field, in the example above I’ve added <strong> tags around the name

    The next is field_delim – this is what is used to join the strings for each field – default is <br /> but you can change this to anything.

    I think with these two arguments there should be no issues with formatting the way you want.

    Thanks

    #31297

    Anonymous
    Inactive

    I’m trying to output the filtered data using your instructions on the Accessing the Search Data page (http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/). However, the outputted field names and respective data are not wrapped in any sort of html tag.

    I would like the output to look something like this:

    <div class=”filterdata”>
    <div class=”fieldname”>Categories:</div>
    <div class=”fielddata”>Community<br/>Arts</div>
    </div>

    Is that possible by manipulating the sf_current_query?

    #30637

    Anonymous
    Inactive

    Just to be clear. The code below:

    <?php

    $sf_current_query = $searchandfilter->get(14458)->current_query();
    echo $sf_current_query->get_field_string(“_sft_category”);

    ?>

    Results: Categories: All Categories

    It doesn’t display the category that the post is assigned to when using the code:

    Categorized in: <?php the_category(); ?>

    #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 ?

    #30310

    Anonymous
    Inactive

    That doesn’t work. I used the following code:

    <?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”);
    ?>

    The output is:

    Categories: All Categories

    What I had before was better since it displayed the proper category.

    What I’m looking for is a way to display:

    Category: CategoryName

    And have the category linked to display the output as if selecting from the dropdown instead of a different layout.

    This is the current page below which is almost there.

    http://whazat.ca/resource-library/

    #28577

    Anonymous
    Inactive

    Hi Ross

    Thanks for getting back to me. Actually I probably didn’t explain myself very well. All I wanted to do was return the results of some simple custom fields in the search results, which I have managed to do in my own clumsy hacking way, by using the get_field for ACF, which works great for me. But I’m having a strange issue with the search results, the post date, which I think is a standard result you would expect to see from your standard results.php template and which I have left in my ‘updated’ version is not automatically showing up – it’s really strange. If I set the CPT published date to something random like two weeks previous it shows in the results, but if I just create a new CPT it just doesn’t show up at all.

    I wonder if you have come across this issue before – I realise I should really start a new thread, and I will if there’s not a straight forward answer.

    Anyway this is my code for returning the Custom Fields with the post_date towards the end:

    while ($query->have_posts())
    {
    $query->the_post();

    ?>
    <div class=”searchresult”>

    <h2>“><?php the_title(); ?></h2>
    <?php $field = get_field(“location”, $post_id, $format_value);
    $value = get_field( “company” );

    if( $value ) {

    echo ‘<div class=”resultcompany”>’;
    echo ‘<h4 class=”resulttitle”>’ . “company” . ‘: </h3>’;
    echo ‘<h4 class=”resultvalue”> ‘ . $value . ‘</h3>’;
    echo ‘</div>’;
    }

    $field = get_field(“deadline”, $post_id, $format_value);
    $value = get_field( “location” );

    if( $value ) {

    echo ‘<div class=”resultlocation”>’;
    echo ‘<h4 class=”resulttitle”>’ . “location” . ‘: </h3>’;
    echo ‘<h4 class=”resultvalue”> ‘ . $value . ‘</h3>’;
    echo ‘</div>’;
    }

    $field = get_field(“deadline”, $post_id, $format_value);
    $value = get_field( “deadline” );

    if( $value ) {

    echo ‘<div class=”resultdeadline”>’;
    echo ‘<h4 class=”resulttitle”>’ . “deadline” . ‘: </h3>’;
    echo ‘<h4 class=”resultvalue”> ‘ . $value . ‘</h3>’;
    echo ‘</div>’;
    }
    ?>

    <p class=”resultpostdate”>Vacancy Posted: <?php the_date(); ?></p>

    </div>

    <?php
    }
    ?>

    Thanks in advance Ross!


    Anonymous
    Inactive

    THANK YOU so much Ross for helping with my prior questions that are now RESOLVED.

    Now I moved my Resources section that uses Search and Filter Pro live http://leadernet.org/featured-resources/ The search output goes to post type archive http://leadernet.org/resources/ .
    When no search is performed I need this archive page title to say “Showing results for all resources” vs YOU SEARCHED FOR: nothing

    I can’t figure it out.
    I can check for the length of of my text entry $my_search_term
    I’m lost trying to have an indicator of none of taxonomy checkboxes being selected.

    $my_search_term = $sf_current_query->get_search_term();
    $taxonomies = $sf_current_query->get_fields_html($fields, $args);
    echo “<br> search term length is” . strlen($my_search_term); — is 0 when none in text box
    echo “<br> term array length is” . count($taxonomies); — always 1 no matter selections

    What am I missing?

    Looking forward to your guidance, Nina

    #26753

    Ross
    Keymaster

    Hi Nina

    It should be like the example I showed you – I’ve reformatted it to make it more readable:

    $fields = array(
    	"_sft_leadership",
    	"_sft_management",
    	"_sft_governance",
    	"_sft_crosscutting"
    );
    
    $args = array(
    	"field_delim" => "<br />",
    	"delim" => ", ",
    	"show_all_if_empty" => true
    );
    
    echo $sf_current_query->get_fields_html($fields, $args);

    field_delim is the delimiter between the data for each field,
    delim is the delimiter between the actual options selected within a field

    Thanks

    #26674

    Anonymous
    Inactive

    Hello again Ross and thank you for your guidance!

    I installed updated plugin. I saw the class code that utilizes replacing args.

    I still have two questions:

    Question 1. if this code is correct – meaning should $args be where it is now:

    echo $sf_current_query->get_fields_html(
    array( “_sft_leadership”, “_sft_management”, “_sft_governance”, “_sft_crosscutting” )
    $args
    );

    OR it should go inside of the () like I’m guessing – please see below

    echo $sf_current_query->get_fields_html(
    array( “_sft_leadership”, “_sft_management”, “_sft_governance”, “_sft_crosscutting”, $args )

    );

    Question 2. After you confirm which version to use, I am not clear where to put this code.
    When I try to add “my guess” version on the top of the archive page I see that args are not being replaced.

    I on purpose changed the args to be explicitly different

    $args = array(
    “field_delim” => “X”,
    “delim” => “,Y “,
    “show_all_if_empty” => false
    );

    But when I use echo to output them, they come as: args are: , , – link to archive page is below
    http://leadernetnina.wpengine.com/resources/?_sf_s=manager&_sft_leadership=leading-change%2Cmotivation

    Sorry for being dense. As I said I’m a beginner.
    Really need your help with this critical project.

    Thank you again, Nina

Viewing 10 results - 171 through 180 (of 188 total)