Search Results for 'get_field'

Forums › Forums › Search › Search Results for 'get_field'

Viewing 10 results – 21 through 30 (of 219 total)
  • Author
    Search Results
  • #248388

    Anonymous
    Inactive

    Hello,

    I have a custom results.php. In this I load a shortcode:

    if (!empty(get_field('_smt-gallery-shortcode'))) {
    					$galleryShortcode = "[foogallery id=" . get_field('_smt-gallery-shortcode') . " paging_size=3]";
    					echo $galleryShortcode;
    					echo do_shortcode("$galleryShortcode");
    				 }

    When th page is loaded the first time everything works fine. When I change the filter and the page is reloaded (ajax on) the shortcode is not shown.

    When I diasble Ajax in the Search&Filter settings the whole page is reloaded and the shortcode is shown.

    What can I do to load the shortcode together with ajax refresh.

    Robert

    #248059

    Anonymous
    Inactive

    Hello,

    I use ACF and Search and Filter Pro for a “calendar like”.

    I have a ACF field type : date (event-date).
    I have a Search And Filter form and i use this meta key (event-date) in a dropdown element.

    The problem i have :
    https://prnt.sc/swnklv
    The display of the date in the dropdown element is différent than the get_field function. I want “10/06/2020” not “20200610”. Where can i change this setting ? I check the ACF config, but the display is correct : https://prnt.sc/swnm3t

    Can you help me please ?


    Anonymous
    Inactive

    The code got all mixed up, so here I have posted it again
    I have couple of issues
    See this page
    https://acu2020dev.wpengine.com/story
    I have created a page template and added the shortcodes

    echo do_shortcode('[searchandfilter id="133"]');
    echo do_shortcode('[searchandfilter id="133" show="results"]');

    I am showing a featured post first and then I am showing the listing
    As I dont want to show the featured post I added the following code

    function filter_function_name( $query_args, $sfid ) {
    //echo “Coming here”;
    
    //if search form ID = 225, the do something with this query
    if($sfid==133)
    {
    //modify $query_args here before returning it
    if (is_page_template(‘page-templates/stories.php’)) {
    //echo “This is “.get_queried_object_id();
    $featured_story = get_field(“featured_story_landingpage”,get_queried_object_id());
    $exclude = array($featured_story->ID);
    $query_args[‘post__not_in’] = $exclude;
    }
    }
    
    return $query_args;
    }
    
    add_filter( ‘sf_edit_query_args’, ‘filter_function_name’, 20, 2 );

    This works alright when the page is loaded, but when I click the Clear filter button or when a category is selected, the above exclusion is ignored and the featured post is shown in the listing
    What am I doing wrong? or is this a bug in the plugin?
    Also how can I show a numbered pagination?
    regards


    Anonymous
    Inactive

    I have couple of issues
    See this page
    https://acu2020dev.wpengine.com/story
    I have created a page template and added the shortcodes

    echo do_shortcode('[searchandfilter id="133"]');
    echo do_shortcode('[searchandfilter id="133" show="results"]');

    I am showing a featured post first and then I am showing the listing
    As I dont want to show the featured post I added the following code

    function filter_function_name( $query_args, $sfid ) {
      //echo "Coming here";
    
      //if search form ID = 225, the do something with this query
      if($sfid==133)
      {
        //modify $query_args here before returning it
        if (is_page_template('page-templates/stories.php')) {
            //echo "This is ".get_queried_object_id();
            $featured_story = get_field("featured_story_landingpage",get_queried_object_id());
            $exclude = array($featured_story->ID);
            $query_args['post__not_in'] = $exclude;
        }
      }
    
      return $query_args;
    }
    
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );

    This works alright when the page is loaded, but when I click the Clear filter button or when a category is selected, the above exclusion is ignored and the featured post is shown in the listing
    What am I doing wrong? or is this a bug in the plugin?
    Also how can I show a numbered pagination?
    regards

    #246600

    Trevor
    Participant

    _sft_meta_value, would, I think, be _sfm_county

    So, you would echo something like this:

    echo $sf_current_query->get_fields_html(array("_sft_category"));
    echo $sf_current_query["_sfm_county"]["active_terms"][0]["value"];

    With County, that code assumes you have just one term selected. If none are selected, you might have first to test if that has a value. Like this:

    echo $sf_current_query->get_fields_html(array("_sft_category"));
    $county = $sf_current_query["_sfm_county"]["active_terms"][0]["value"];
    if ($county) {
    echo $county;
    } else {
    echo "All Counties";
    }

    If you allow more than one county, it would get a little more complicated, but not much.

    #246593

    Trevor
    Participant

    So, what does this code do?

    $test_price = get_field('test_price');
    if( $test_price ) echo "CHF " . number_format( $test_price,,".-" ,"’");
    #246563

    Trevor
    Participant

    Let us do this in steps. Make a snippet named show_price and set it to PHP and Shortcode like this with this code:

    https://www.screencast.com/t/XE4JLnu9wCuy

    Code used:

    echo "this is the price";

    Then, in the Text tab of a Text editor, place the shortcode:

    [show_price]

    And see if that works (shows that message)? If it does …

    Make a test ACF field for the cars, named test_price, in one car add the raw price.

    Change the snippet to this:

    $test_price = get_field('test_price');
    if( $test_price ) echo $test_price;

    Check to see if on that car’s page, that worked? Then, if it does, we need to format the number.

    #246480

    Anonymous
    Inactive

    On NovaScotiaFood.com I have a search form that uses AND as an operator. The user simply selects a category of food producer and a county, and they get a list of that type of food producer in the selected county. The search works fine. The results are not yet displaying the way I’d like.

    I’ve just copied some of your example code on my results page:

    <?php
    	//Get a multiple fields values by passing an array of field names
    	//replace <code>1526</code> with the ID of your search form
    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(1949)->current_query();
    
    	/*
    	 * EXAMPLE 1 
    	 */
    
    	echo $sf_current_query->get_fields_html(
    		array("_sft_category", "_sft_meta_value")
    	);

    where I just tried to guess that ‘_sft_meta_value’ would output the custom field entry that was searched for, but I guessed wrong. What should I be putting in there instead to correctly output the custom field? Thanks.

    #245136

    Trevor
    Participant

    This is what I see. To get the fields to show in the results you would need to code them into the template, using this guide:

    https://searchandfilter.com/documentation/search-results/using-a-shortcode/#customising-the-results

    The extra code would likely need to look like this:

    <?php $county = get_field('county');
    if( $county ) { ?>
    <div class="county-field">County: <?php echo $county; ?></div>
    <?php } ?>
    #241098

    Anonymous
    Inactive

    Pagination doesn’t” work properly

    Hello. I am using search and Filter pro and having problem with pagination.
    It seems to work fine but when I go back to page 1, only page 1 doesn’t have the link(doesn’t have href).
    And it happens only PC view, if I check with SP, it works just fine.

    Here is My code.
    (*I use original code for pagination, but if tried to use WP-PageNavi(same as your template of results.php) Page 1 doesn’t work either.)

    [results.php]

    <?php
    if ($query->have_posts()) : ?>
    <?php
        while ($query->have_posts()) {
            $query->the_post(); ?>
    <a href="<?php the_permalink(); ?>" class="sresult">
      <?php
          if (has_post_thumbnail()) {
              echo '<p class="sresult-thumb">';
              the_post_thumbnail();
              echo '</p>';
          } ?>
      <h2 class="sresult-ttl"><?php the_title(); ?></h2>
      <p class="sresult-name"><?php the_field('interview_name'); ?>
      </p>
      <?php
          $fields = get_field_objects($post_id);
            $dir_array = $fields["interview_occupation"]["choices"];
            $check = get_field('interview_occupation');
            $value = $check[0]; ?>
      <p class="sresult-job"><?php echo $dir_array[$value]; ?></p>
    
    </a><!-- /.sresult -->
    
    <?php } ?>
    
    <div class="spagination">
      <?php
        if ( function_exists( 'pagination' ) ) :
            pagination( $query->max_num_pages, get_query_var( 'paged' ) ); 
        endif;
      ?>
    </div><!-- /.spagination -->
    
    <?php else : ?>
      <div class="snoresult">
        <p>No results</p>
      </div><!-- /.snoresult -->
    <?php endif; ?>
    
    </div><!-- /. search-filter-results -->

    [functions.php]

    function pagination( $pages, $paged, $range = 2, $show_only = false ) {
    
      $pages = ( int ) $pages;    
      $paged = $paged ?: 1;       
    
      //表示テキスト
      $text_first   = "« FIRST";
      $text_before  = "PREV";
      $text_next    = "NEXT";
      $text_last    = "LAST »";
    
      if ( $show_only && $pages === 1 ) {
        
        echo '<div class="pagination"><span class="current pager">1</span></div>';
        return;
      }
    
      if ( $pages === 1 ) return;    
    
      if ( 1 !== $pages ) {
        
        echo '<div class="pagination"><span class="page_num">Page ', $paged ,' of ', $pages ,'</span>';
        if ( $paged > $range + 1 ) {
          // FIRST
          echo '<a href="', get_pagenum_link(1) ,'" class="first js_redirect_to_pagenum_link">', $text_first ,'</a>';
        }
        if ( $paged > 1 ) {
          // PREV
          echo '<a href="', get_pagenum_link( $paged - 1 ) ,'" class="prev js_redirect_to_pagenum_link">', $text_before ,'</a>';
        }
        for ( $i = 1; $i <= $pages; $i++ ) {
          if ( $i <= $paged + $range && $i >= $paged - $range ) {
            // $paged +- $range 以内であればページ番号を出力
            if ( $paged === $i ) {
                echo '<span class="current pager">', $i ,'</span>';
            } else {
              echo '<a href="', get_pagenum_link( $i ) ,'" class="pager js_redirect_to_pagenum_link">', $i ,'</a>';
              }
            }
        }
        if ( $paged < $pages ) {
          // NEXT
          echo '<a href="', get_pagenum_link( $paged + 1 ) ,'" class="next js_redirect_to_pagenum_link">', $text_next ,'</a>';
        }
        if ( $paged + $range < $pages ) {
          // LAST
          echo '<a href="', get_pagenum_link( $pages ) ,'" class="last js_redirect_to_pagenum_link">', $text_last ,'</a>';
        }
        echo '</div>';
      }
    }

    The website is my client site so I cannot give you the link. But if you provide me a contact address that I can send you directly or hide this topic somehow, I can give you the link of testsite.

    Regards,

Viewing 10 results – 21 through 30 (of 219 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.