Forums Forums Search Search Results for 'get_field'

Viewing 10 results - 101 through 110 (of 188 total)
  • Author
    Search Results
  • #169120

    Anonymous
    Inactive

    Hi,

    Have an issue trying to extract post types via $postTypes1 = $sf_current_query->get_fields_html(array(“_sf_s”, “_sft_access_level”, “post_type”,”_sft_topic”));
    echo $postTypes1;

    only returns
    Access Levels: All Access Levels (ie: _sft_access_level)
    Topics: All Topics (ie: _sft_topic)

    but no post types aka Data Type.

    You can see the page results here:

    The debug structure of the query which clearly shows them here:
    Please see image link
    or
    Issue with get_fields_html

    Is this a bug with get_fields_html?

    If the Data Types are checked as filters it’s possible to retrieve them but that is different from retrieving the associated post types via get fields.

    	<?php  	
    		$postTypes1 = $sf_current_query->get_fields_html(array("_sf_s", "_sft_access_level", "post_type","_sft_topic"));
    		echo $postTypes1; 
    		//echo $sf_current_query->is_filtered();
    		$postTypesAll = $sf_current_query->get_array();
    		//var_dump($postTypesAll);
    		//print_r(array_values($postTypesAll));
    		$postTypes = array_column($postTypesAll, 'active_terms');
    		//var_dump($postTypes);
    		//print_r(array_values($postTypes));
    		$newArray = array();
    		foreach ($postTypes as $entry) {
    			$names = array_column($entry, 'name');
    		}
    		//var_dump($names);
    		//print_r(array_values($names));
    		$dataTypes = "<br>Data Types: ";
    		$breakChars = ", ";
    		//echo $dataTypes;
    		for ($i = 0; $i < count($names); $i++) {
    			$nameCompare = strcmp($names[$i], "Posts");
    			if ($nameCompare == 0) {
    				$names[$i] = 'Articles';
    			}
    			//echo $names[$i];
    			if ($i < count($names) - 1) {
    				echo $breakChars;
    			}
    		}
    		//var_dump($names);
    		//print_r(array_values($names));
    	?>

    Trevor
    Participant

    Ah, I see. You have three possible output combinations.

    Try this:

    <?php global $searchandfilter;
        $sf_current_query = $searchandfilter->get(2398)->current_query();
        $searchTerm = $sf_current_query->get_search_term();
          $args = array(
          "str"           => '%2$s', 
          "delim"         => array(", ", " - "), 
          "field_delim"       => ', ', 
          "show_all_if_empty"     => false 
        );
      ?>
    
    <?php global $wp_query;
    $fields_html = $sf_current_query->get_fields_html( array("_sft_clinical-area", "_sft_program", "_sft_type"), $args);
        if (( $searchTerm <> "" ) && ( $fields_html <> "" ) ){
          $field_delim = ', ';
        } else {
          $field_delim = '';
        }
    
              echo $wp_query->found_posts; ?>
              Search Results for <?php echo $searchTerm . $field_delim . $fields_html; ?>

    Maybe?

    #163253

    Anonymous
    Inactive

    Hello,

    In my search form UI I have a search form and multiple post meta acf checkbox

    I tried :

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(53)->current_query();
    echo $sf_current_query->get_search_term();
    ?>

    It display only search terms of the search form, not post meta acf checkbox one !

    So I tried :

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(53)->current_query();
    $args = array(
    “str” => ‘%2$s’,
    “delim” => array(“, “, ” – “),
    “field_delim” => ‘, ‘,
    “show_all_if_empty” => false
    );

    echo $sf_current_query->get_fields_html(
    array(“_sf_s”, “_sfm_nom-de-l-artiste”, “_sfm_prenom-du-commissaire”, “_sfm_lieu”, “_sfm_nom-du-medium”, “_sfm_forme-de-la-carte”, “_sfm_couleur”, “_sfm_ecole-du-commissaire”, “_sfm_jour-de-la-visite”, “_sfm_age-du-commissaire”),
    $args
    );
    ?>

    But it displays nothing !

    Can you help me and telle me what I did wrong ?

    Thank you very muche
    Best regards,
    Juke

    #157375

    Anonymous
    Inactive

    Hi Trevor,

    Thanks for the quick response.

    I can get it to half work… This search query should yield the response:
    “Search Results for: green Brexit, Legatum Institute, Posts”
    http://smartthinking.staging.wpengine.com/?sfid=979&_sf_s=green&_sft_category=brexit&_sfm_think_tank=Legatum%20Institute&post_types=post#a

    At least that is what I would like it to do. But currently only the category is showing.

    This is the markup:

    <?php
        global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(979)->current_query(); ?>
                        
                
        <h1 class="archive_title"><span><?php _e("Search Results for","wpbootstrap"); ?>:</span> <?php echo esc_attr(get_search_query()); ?>
                            
             <?php              
            $args = array(
                "str" 					=> '%2$s', 
                "delim" 				=> array(", ", " - "), 
                "field_delim"				=> ', ', 
                "show_all_if_empty"			=> false 
            );
            
            echo $sf_current_query->get_fields_html(
                array("_sft_category", "_sft_post_tag", "_sft_sfdc_post_type", "_sft_sfdc_think_tank"), 
                $args
            );
            ?>
            
        </h1>

    Have I done something wrong?
    Thanks,
    Alex


    Ross
    Keymaster

    Hi Boris

    Yes, well it looks like you don’t even need our filter for your needs.

    If you want to exclude options from your field, simply hit “advanced” (in S&F admin, search form UI) and there you can enter the IDs you wish to exclude.

    The classes, hmm, we added a filter to change the classes on the input objects (<input>) but not on the containing <li>.

    However, since the version you used, you will notice, we have now added our own classes on to all the <li>, with appropriate names, such as sf-field-search on the search box – take a look at the the source code we generate now – its much better than before.

    I think its better you update your CSS to use our class names… Otherwise you will need to make changes in the files:
    public/includes/class-search-filter-generate-input.php
    public/includes/class-search-filter-display-shortcode.php (look for function get_field)

    Thanks

    #151119

    Anonymous
    Inactive

    haha yes. That makes total sense, and it’s working as expected now. I was testing the output at the top of the file without thinking about where the results refresh…

    One more thing… I would like to wrap the label and term in markup. Is there a way to return the label and term values separately?
    For instance, echo $sf_current_query->get_field_string("_sft_location"); returns “Location: Africa”, but I would like it to read <dt>Location:</dt><dd>Africa</dd>.

    Thanks!

    #140420

    In reply to: Some Ui questions


    Anonymous
    Inactive

    Hi Trevor, got a little further with styling so thanks for that. One thing with accessing the search data so I can display what’s been searched for – i’ve looked at

    https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    but am not getting any output. I’m using ACF meta fields for all the search criteria so maybe I need to use something differently?

    ?_sfm_comfort=medium&_sfm_value_judgement=bestquality&_sfm_state=wa
    is the query string

    i’m using this in the custom page template:

    echo $sf_current_query->get_fields_html(
    array(“_sfm_comfort”)
    );

    echo $sf_current_query->get_field_string(“_sfm_comfort”);

    also doesn’t give any result.

    the var dump gives:
    array(3) { [“_sfm_comfort”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(6) “Medium” [“value”]=> string(6) “medium” } } } [“_sfm_value_judgement”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(12) “Best Quality” [“value”]=> string(11) “bestquality” } } } [“_sfm_state”]=> array(5) { [“name”]=> string(0) “” [“singular_name”]=> string(0) “” [“all_items_label”]=> string(0) “” [“type”]=> string(9) “post_meta” [“active_terms”]=> array(1) { [0]=> array(2) { [“name”]=> string(2) “WA” [“value”]=> string(2) “wa” } } } }

    help appreciated – cheers
    Mike

    #139818

    Trevor
    Participant

    Hi

    Your code isn’t inside back ticks (code ticks) so it is hard to read, so I have recoded it here, and towards the end added a line to remove the final comma that the code adds (it adds the ID plus a comma each time, but the last comma is not needed):

    <?php
    $map_sc_text='[wpgmza id="5" mashup=true mashup_ids="';
    
    while ($query->have_posts())
    {
    $query->the_post();
    
    ?>
    <div>
    <h2><?php the_title(); ?></h2>
    
    <p><br /><?php the_excerpt(); ?> </p>
    <?php
    if ( has_post_thumbnail() ) {
    echo '<p>';
    the_post_thumbnail("small");
    echo '</p>';
    }
    ?>
    <p><?php the_category(); ?></p>
    <p><?php the_tags(); ?></p>
    
    </div>
    
    <hr />
    <?php
    
    $map_sc_text.=get_field('hotel_map_id').',';
    }
    $map_sc_text=substr($map_sc_text,0,-1);
    $map_sc_text.='" parent_id="5"]';
    do_shortcode($map_sc_text);
    
    ?>

    Does that work?

    #139694

    Anonymous
    Inactive

    Hi Trevor,

    Thanks to your amazing help, I was able to also make something like this work with that maps plugin you mention above.

    Here’s the maps code I placed on the results.php page in my child theme (the ACF field for the map ID is called “hotel_map_id”):

    <?php
    $map_sc_text='[wpgmza id=”5″ mashup=true mashup_ids=”‘;

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

    ?>
    <div>
    <h2>“><?php the_title(); ?></h2>

    <p><br /><?php the_excerpt(); ?> </p>
    <?php
    if ( has_post_thumbnail() ) {
    echo ‘<p>’;
    the_post_thumbnail(“small”);
    echo ‘</p>’;
    }
    ?>
    <p><?php the_category(); ?></p>
    <p><?php the_tags(); ?></p>

    </div>

    <hr />
    <?php

    $map_sc_text.=get_field(‘hotel_map_id’).’,’;
    }

    $map_sc_text.='” parent_id=”5″]’;
    do_shortcode($map_sc_text);

    ?>

    However, even though the functionality is perfect, I now get this error (only on the search and results page, not the whole site):

    Warning: Invalid argument supplied for foreach() in /wp-content/plugins/wp-google-maps-pro/wp-google-maps-pro.php on line 3570.

    Did you by any chance come across this issue when you were doing this? If so, how did you fix it?

    Thank you so so much!

    Maria

    #138347

    Trevor
    Participant

    There is no set answer for a question like that. It first depends, in the form settings, what Display Results Method you are using. In turn, this will determine what template php file you are using, as you code will need to fetch the data from the ACF field. However, javascript is not the way. Use PHP instead to fetch the ACF data, and then create some inline CSS based on what is fetched. I wrote something like this a while ago, where on each post the user could select an image to be used as a parallax background image at the top of the post. The code looked like this (used in the loop part of the page template):

    <?php
    $banner_image = get_field('banner_image');
    if ( !empty($banner_image) ) {
      echo '<style>.banner-image-wrapper {background-image: url("' . $banner_image['url'] . '");background-repeat: no-repeat;background-size: cover;}</style>';
    } else {
      echo '<style>.banner-image-wrapper {display: none;}</style>';
    }
    ?>

    and there is a row in the template that has that class attached.

Viewing 10 results - 101 through 110 (of 188 total)