Forums Forums Search Search Results for 'get_field'

Viewing 10 results - 1 through 10 (of 188 total)
  • Author
    Search Results
  • #268116

    Anonymous
    Inactive

    I tried following this: https://searchandfilter.com/documentation/accessing-search-data/

    on this page: http://staging2.iconcasterwheels.com/shop/?_sfm_caster-wheel-size=10%22&_sfm_caster-wheel-material=Air%2FFlat%20Free&_sfm_caster-fastening-type=Top%20Plate&_sfm_caster-load-capacity=200+300

    Here is the code:

    global $searchandfilter;
    	  $sf_current_query = $searchandfilter->get(56)->current_query();
          //var_dump($sf_current_query->get_array());
    
          $searchArgs = array(
            "str" 					=> '%2$s', 
            "delim" 				=> array(", ", " - "), 
            "field_delim"			=> ', ', 
            "show_all_if_empty"		=> false 
          );
    	  
          
          echo $sf_current_query->get_fields_html(
            array(
              "_sfm_caster-wheel-size",
              "_sfm_caster-wheel-material",
              "_sfm_caster-fastening-type",
              "_sfm_caster-load-capacity"
            ), 
            $searchArgs
          );
    
    

    When I do a var_dump, it shows the info that is expected (hidden for now) — so the id and everything seems to be correct.
    However, when I try to display any of the field values, nothing shows up.

    No errors in console message or anything either.

    I am trying to get it to say “Search Results 10″, Air Flat/Free, Top Plate”

    #267925

    Anonymous
    Inactive

    Hi Trevor,

    Sorry, I think there was a typo on the category search term. I wanted to have an if statement that will check whether the search query has _sft_category. Then if that is true, I wanted to automatically reset the query to remove everything including the _sft_category.

    Currently, I have this code as a start but was stuck on how to call the reset function.

    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1184)->current_query();
    
    if ( $sf_current_query->get_field_string("_sft_category") ) :
      // reset the search query here
    endif;
    

    Thanks!

    #267502

    Anonymous
    Inactive

    https://prnt.sc/vodelo Hi, by default I want to active Projections taxonomy when a user comes to this page. Is it possible then how?

    here is my code:

    <?php
    /* 
       Template Name: analysis
    */
    get_header();
    
    	$ourCurrentPage = get_query_var('paged');
        $args = array(  
       'post_type' => 'analysis',
       'post_status' => 'publish',
       'posts_per_page' => 10,
       'taxonomy' => 'projections',
       'paged' => $ourCurrentPage
        );
        $args['search_filter_id'] = 1605;
        $the_query = new WP_Query( $args );?>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/venobox/1.9.1/venobox.min.css" integrity="sha512-e+0yqAgUQFoRrJ4pZigQXpOE0S7J9IGwmgH801h4H5ODqOCG8/GRfXHQ+9ab754NL79O7wDwdjwY3CcU8sEANg==" crossorigin="anonymous" />
        <style>
            .f1p{display:flex;flex-wrap:wrap;max-width:900px;margin:auto;}.grant-parent{width:30%;margin:1%;padding:15px;background:#fff;border:1px solid #e5e5e5;border-radius:4px;}.heding.ccount{font-size:15px;margin-bottom:0px;}.pagination{width:100%;}
        </style>
                <div class="f1b-main" style="padding-top:30px;">
                    <?php echo do_shortcode('[searchandfilter id="1605"]'); ?>
                    <div class="f1p">
                        <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                        <?php $image = get_field( 'image' );?>
                        <div class="fl grant-parent">
                            <P class="heding ccount"><?php echo get_field( "date" );?></P>
                            <?php 
                                foreach((get_the_terms( $post->ID, 'analysis' )) as $category){
                                    echo "<p><a class='venobox' data-gall='$category->name' href='$image' data-title='the_title()'><img src='$image' /></a></p>";
                                }
                            ?>
                            <p class="heding ccount" title="<?php the_title(); ?>"><b><?php the_title(); ?></b></p>
                        </div>
    
                        <?php endwhile; ?>
    
                        <div class="pagination">
                            <h2><?php echo paginate_links(array(
                        'total' => $the_query->max_num_pages
                        ));
                        ?></h2>
                        </div>
    
                        <?php else : ?>
                        <div class="not-found">
                            <p><?php  _e( 'Sorry, no products matched your criteria.'); ?></p>
                        </div>
                        <?php endif; ?>
    
                        <?php wp_reset_postdata(); ?>
    
                    </div>
                </div>
     <script src="https://cdnjs.cloudflare.com/ajax/libs/venobox/1.9.1/venobox.min.js" integrity="sha512-6mm1Gra+9mSztlk6Q45F1soEHmkduyd2ponCIWNo5pr0lgcr8d79GQjQ3Nw0uRR3/+y/OZGklAi38yE1QSNpCw==" crossorigin="anonymous"></script>
     <script>
     jQuery('input[value="projections"]').trigger( "click" );
     jQuery('.venobox').venobox(); 
        (function($) {
            "use strict";
            jQuery(document).on("sf:ajaxfinish", ".searchandfilter", function() {
                jQuery('.venobox').venobox();
            });
        }(jQuery));
    </script>
    
    <?php do_action( 'kadence_single' );
    get_footer();

    Anonymous
    Inactive

    Hi Trevor,
    thanks for your reply.
    You can see filter and results on this page: https://gesunder-wmk.de/zzzzzzzzztest-mehr-wissen/

    This code:
    ———————————
    <?php
    $args = array(
    ‘posts_per_page’ => 100,
    ‘order’ => ‘DESC’,
    ‘orderby’ => ‘title’,
    ‘post_type’ => ‘mehr-wissen’,
    );
    $args[‘search_filter_id’] = 5565;
    // the query
    $the_query = new WP_Query( $args );
    if ( $the_query->have_posts() ) :
    // the loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    ?>
    <div class=”mw-wrapper”>
    <div class=”mw-header”>
    <figure><?php the_post_thumbnail(); ?></figure>
    <div class=”headlines”>
    <h2><?php the_title(); ?></h2>
    <?php if(get_field(‘headline_2’)) { echo ‘<h3>’ . get_field(‘headline_2’) . ‘</h3>’; } ?>
    <?php if(get_field(‘subline_zu_headline_2’)) { echo ‘<p>’ . get_field(‘subline_zu_headline_2’) . ‘</p>’; } ?>
    </div>
    </div>

    <div class=”mw-content”>
    <?php the_content(); ?>
    </div>
    </div>

    <?php
    endwhile;
    // end of the loop
    wp_reset_postdata();
    else :?>
    <p><?php _e( ‘Sorry, no posts matched your criteria.’ ); ?></p>
    <?php endif;
    ?>
    ——————————–
    I added the code by creating a divi module with the plugin Divi Module Builder by Divi Plugins.

    Greetings
    Sandra


    Anonymous
    Inactive

    We’ve recently upgraded to the latest version of Search and Filter pro.

    The old version was setup by someone else. We are using a custom template to display search results, with custom taxonomies for the product pages.

    The filtering no longer works, and we are struggling to get multiple pages for results as the we can’t seem to figure our the “loop” for display our results with the information attached.

    Archive page below:

    <?php get_header(); ?>

    <div class=”page-header available”>

    <div class=”container”>

    <?php echo do_shortcode(‘[searchandfilter id=”79″]’); ?>

    </div></div>

    <div class=”full-width-content”>

    <div class=”container”>
    <div class=”sculpture-intro”><h1 style=”font-size:x-Large;”>Sculpture Collection
    </h1><br>

    </div>
    <div class=”row”>

    <div class=”col-md-12″>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <article class=” sculpture_post”>
    <div class=”archive-thumb”>

    “> <?php the_post_thumbnail( ‘archive-thumb’ ); ?>
    </div>

    <h1 class=”archive”>“><?php the_title(); ?></h1>
    <p><?php the_category( ‘, ‘ ); ?></p>
    <div class=”artistt-archive”>
    <?php

    $term = get_field(‘artist’);

    if( $term ): ?>

    <p>by <?php echo $term->name; ?></p>

    <?php endif; ?>
    </div>

    <p><?php the_field(‘price’); ?></p>

    <?php

    $term = get_field(‘size’);

    if( $term ): ?>

    <p>size: <?php echo $term->name; ?></p>

    <?php endif; ?>

    </article>

    <?php endwhile; else: ?>
    <br>
    <div class=”no-result”>
    <h1>sorry! no sculptures match your criteria</h1>
    <br>
    Reset Search
    </div>

    <?php endif; ?>

    </div>

    </div>

    <?php get_footer(); ?>

    #263487

    Trevor
    Participant

    To display an ACF field (make sure you get the field name right in our plugin, they do NOT start with an underscore), code like this:

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

    Of course, you might put some HTML around that, not might want something else if no value found …

    As to the taxonomies, would they have single or multiple terms per post?

    #259160

    Anonymous
    Inactive

    I have integrated a list of active filters and I would like to introduce them with the same title as in the search list.
    In other words, for a filter on the taxonomy “places”, “whose label “singular_name” must remain “Place”, I have created a field whose heading is “Place of birth”.
    When the user chooses, for example, “Paris” as “Place of birth”, I add at the top of the results list “Place of birth: Paris”.
    I have seen solutions using get_fields_html or get_array, but both methods use the singular_name of the taxonomy and not the heading of the field.
    I hope I’m clear 🙂

    #257057

    Anonymous
    Inactive

    <?php
    if ( ! defined( ‘ABSPATH’ ) ) { exit; }

    if ( ! isset( $content_width ) ) $content_width = 1280;

    function skelementor_init() {

    add_theme_support( ‘title-tag’ );
    add_theme_support( ‘post-thumbnails’ );
    add_theme_support( ‘automatic-feed-links’ );
    add_theme_support( ‘title-tag’ );
    add_theme_support( ‘html5’, array( ‘search-form’, ‘comment-form’, ‘comment-list’, ‘gallery’, ‘caption’ ) );
    add_theme_support( ‘custom-logo’, array(
    ‘width’ => 260,
    ‘height’ => 100,
    ‘flex-height’ => true,
    ‘flex-width’ => true,
    ) );
    add_theme_support( ‘custom-header’ );
    add_theme_support( ‘woocommerce’ );
    add_post_type_support( ‘page’, ‘excerpt’ );

    register_nav_menus(
    array( ‘main-menu’ => __( ‘Main Menu’, ‘skelementor’ ) )
    );

    load_theme_textdomain( ‘skelementor’, get_template_directory() . ‘/languages’ );
    }
    add_action( ‘after_setup_theme’, ‘skelementor_init’ );

    function skelementor_comment_reply() {
    if ( get_option( ‘thread_comments’ ) ) { wp_enqueue_script( ‘comment-reply’ ); }
    }
    add_action( ‘comment_form_before’, ‘skelementor_comment_reply’ );

    function skelementor_scripts_styles() {
    wp_enqueue_style( ‘skelementor-style’, get_stylesheet_uri() );
    }
    add_action( ‘wp_enqueue_scripts’, ‘skelementor_scripts_styles’ );

    function skelementor_register_elementor_locations( $elementor_theme_manager ) {
    $elementor_theme_manager->register_all_core_location();
    };
    add_action( ‘elementor/theme/register_locations’, ‘skelementor_register_elementor_locations’ );

    function price_range_on_save( $post_id ) {
    $post_type = ‘share’; //custom post type for events

    //Check if we are saving correct post type
    if( get_post_type( $post_id ) != $post_type)
    return;

    //Check it’s not an auto save routine
    if( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE )
    return;

    // get the price of the post. This assumes that the price is a number and has no currency symbol or thousands separator
    $post_price = get_post_field (‘price’, $post_id);
    // set an empty default string
    $post_price_text = “”;
    // set the price text label to match the price
    if ($post_price) {
    switch($post_price) {
    case ( $post_price <= 100 ):
    $post_price_text = “0-100 kr”;
    break;
    case ( ($post_price > 100) && ($post_price <= 250) ):
    $post_price_text = “101-250 kr”;
    break;
    default:
    $post_price_text = “250 kr and up”;
    }
    }

    // update the price choice
    update_field( ‘post_price_text’, $post_price_text );
    }
    add_action(‘save_post’, ‘price_range_on_save’);

    /////////
    $roots_includes = array(
    ‘lib/extras.php’,
    ‘lib/scripts.php’,
    ‘lib/ajax.php’,
    ‘lib/post-types.php’,
    ‘lib/init.php’,
    ‘lib/utilities.php’,
    ‘lib/acf.php’,
    // ‘lib/custom-fields.php’,
    // ‘lib/custom-fields/category.php’,
    // ‘lib/custom-fields/footer.php’,
    // ‘lib/custom-fields/post.php’,
    );

    foreach ($roots_includes as $file) {
    if (!$filepath = locate_template($file)) {
    trigger_error(sprintf(__(‘Error locating %s for inclusion’, ‘roots’), $file), E_USER_ERROR);
    }

    require_once $filepath;
    }
    unset($file, $filepath);

    // CUSTOM FILTER // Add author of the current post (SPELTIPS)
    add_action( ‘elementor/query/from_same-author’, function( $query ) {
    // The author of the current post
    $author_id = get_the_author_meta(‘ID’);
    $query->set( ‘author’, $author_id );
    } );

    // CUSTOM FILTER // Add Speltips from same expert on EXPERT page
    add_action( ‘elementor/query/spel-from-same-expert’, function( $query ) {
    // The author of the current post

    $author_id = get_field( ‘wp_authors’ );

    $query->set( ‘author’, $author_id );
    } );

    add_action( ‘elementor/query/shares-from-current_author’, function( $query ) {
    // The author of the current post

    $author_id = get_the_author_meta(‘ID’);

    $expert_id = get_field( ‘expert’, ‘user_’ . $author_id );

    if( is_array( $expert_id ) ) $expert_id = $expert_id[ ‘ID’ ];

    $meta_query = $query->get( ‘meta_query’ );

    if( ! is_array( $meta_query ) ) $meta_query = [];

    $meta_query[ ‘expert_id’ ] = [
    ‘key’ => ‘expert’,
    ‘compare’ => ‘==’,
    ‘value’ => $expert_id,
    ];

    $query->set( ‘meta_query’, $meta_query );
    } );

    // CUSTOM FILTER // Add ANDELAR (SHARES) from same expert on EXPERT page
    add_action( ‘elementor/query/andelar-from-same-expert’, function( $query ) {
    // The author of the current post
    $expert_id = get_the_ID();
    $meta_query = $query->get( ‘meta_query’ );

    if( ! is_array( $meta_query ) ) $meta_query = [];

    $meta_query[ ‘expert_id’ ] = [
    ‘key’ => ‘expert’,
    ‘compare’ => ‘==’,
    ‘value’ => $expert_id,
    ];

    $query->set( ‘meta_query’, $meta_query );
    } );

    // Add Options Page
    function add_my_options_page() {
    if( function_exists(‘acf_add_options_page’) ) {
    acf_add_options_page();
    }
    }
    add_action( ‘plugins_loaded’, ‘add_my_options_page’ );

    // Don’t put anything except includes in this file
    //Pick a place for your jsons to live. We stick them into the /theme/includes/acf-json folder, but you can stick these wherever

    // change where acf json files are saved
    add_filter(‘acf/settings/save_json’, ‘jb_acf_save_json’);
    function jb_acf_save_json($path) { return get_stylesheet_directory().’/includes/acf-json’; }

    // add our custom folder to places acf json are loaded from
    add_filter(‘acf/settings/load_json’, ‘jb_acf_load_json’);
    function jb_acf_load_json($paths) { return array_merge($paths, array(get_stylesheet_directory().’/includes/acf-json’)); }

    function custom_theme_slug_filter_the_content( $content ) {
    global $wpdb;
    if(“post” == get_post_type()){
    //if(is_singular(‘posts’)){
    $requested_post_id = get_the_ID();
    $authordetails = get_field(‘acfe_author’, $requested_post_id);
    $suthorname = $authordetails[‘display_name’];
    $expert_args = array(
    ‘post_type’ => ‘expert’,
    ‘post_status’ => ‘publish’,
    ‘title’ => trim($suthorname),
    ‘orderby’ => ‘date’,
    ‘order’ => ‘DESC’
    );
    $query = new WP_Query($expert_args);
    $postid = $query->post->ID;
    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $postid ), ‘full’ );
    $custom_content = ‘<div id=”ctm-img-box” class=”custom-img-box”><span class=”elementor-icon-list-icon”></span><span class=”authorname”>’.$suthorname.'</span></div>’;
    $custom_content .= $content;
    //return $custom_content;
    }else{
    $custom_content = $content;
    }
    return $custom_content;
    }
    add_filter( ‘the_content’, ‘custom_theme_slug_filter_the_content’, 1);

    function wpa_choose_ad($user_id, $expert_id) {
    $requested_post_id = get_the_ID();
    $expert_user = get_field(‘wp_authors’, $requested_post_id);
    //echo $user_id;
    $args = array(
    ‘post_type’ => ‘share’,
    ‘posts_per_page’ => 12,
    ‘orderby’ => ‘rand’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘expert’,
    ‘value’ => $expert_id,
    ‘compare’ => “=”
    )
    )
    );
    $the_query = new WP_Query( $args );
    //echo “

    ";
        //print_r($the_query);
        $the_ad = '<div class="elementor-container elementor-column-gap-no">';
        	$the_ad .= '<div class="element-row">';
        	$the_ad .= '<div class="elementor-widget-container elementor-widget-heading"><h4 class="elementor-heading-title elementor-size-default">MINA ANDELAR</h4></div>';
        $the_ad .= '<div class="elementor-widget-container">';	
        $the_ad .= '<div class="ecs-posts elementor-posts-container elementor-posts elementor-grid elementor-posts--skin-custom">';
        if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) : $the_query->the_post();
        		$title = get_the_title();
        		$url = get_permalink(get_the_ID());
    			$expert_type = get_field('type', get_the_ID());
    			$expert_shares = get_field('shares', get_the_ID());
    			$expert_price = get_field('price', get_the_ID());
    
    		$the_ad .= '<div class="share_outer_box">';
    		$the_ad .= '<div class="share_price_details">';
    		$the_ad .= '<p>'.$expert_type.'</p>';
    		$the_ad .= '<p>'.$expert_shares.' andler | '.$expert_price.' SEK</p>';
    		$the_ad .= '</div>';
    		$the_ad .= '<h2 class="custom-title elementor-heading-title elementor-size-default">'.$title.'</h2>';
    				   	
    		$the_ad .= '</div>';
        endwhile;
        }
        $the_ad .= '</div>';
        $the_ad .= '</div>';
        $the_ad .= '</div>';
        $the_ad .= '</div>';
        wp_reset_postdata();
    
        return $the_ad;
    }
    
    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 19856, the do something with this query
    	if($sfid==19856)
    	{
    		//modify $query_args here before returning it
    		// args
    			$args = array(
    				'post_type'		=> 'shares',
    				'meta_query'	=> array(
    				'relation'		=> 'OR',
    			array(
    			'key'		=> 'type',
    			'value'		=> 'Europatipset',
    			'compare'	=> 'LIKE'
    			),
    			array(
    			'key'		=> 'type',
    			'value'		=> 'Stryktipset',
    			'compare'	=> 'LIKE'
    			)
    	)
    );
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    #253140

    Anonymous
    Inactive

    Just FYI, I have added this code within my #main container on the archive template. Nothing shows.

    	global $searchandfilter;
    	$sf_current_query = $searchandfilter->get(9490)->current_query();
    	echo $sf_current_query->get_field_string("_sfm_UnitLocation");
    #252103

    Anonymous
    Inactive

    Hello!

    I’m currently working on project, where I need to print a table with information – I’ve made a custom post type with Advanced Custom Fields, which I’m printing in the results.php because I’m using the built-in AJAX filtering from Search & Filter. My goal is to make it possible to sort when clicking on one of the th – first click could be ASC and second could be DESC.

    Anything would help,
    Thanks in advance!

    
    <?php
    if ( $query->have_posts() )
    {
    	?>
    	<div class="lej-table-info-table">
    	<table>
    	    <tr>
                <th>Adresse</th>
                <th>Areal</th>
                <th>Værelser</th>
                <th>Pris</th>
                <th class="no-mo">Type</th>
                <th>Status</th>
            </tr>
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    		
    		$status = strip_tags(get_the_term_list( $post->ID, 'status', '', ', ', '' ));
    		?>
            
    			<tr class="table-link" name="<?php global $post; echo $post->post_name; ?>">
                    <td class="no-de"><?php echo $navn = get_field( "navn"); ?></td>
    				<td class="no-mo"><?php echo $navn = get_field( "adresse"); ?></td>
                    <td><?php echo $value = get_field( "areal"); ?> m²</td>
                    <td><?php echo $vaerelser = get_field( "vaerelser"); ?></td>
    			<?php if ($status == 'ledig') { ?>
    				<td class="pris"><?php echo $value = get_field( "kontantpris" ); ?></td>
    			<?php } else { ?>
    				<td></td>
    			<?php } ?>
                    
                    <td class="no-mo"><?php echo $value = get_field( "lejlighedstype" ); ?></td>
                    <!--<td class="<?php echo strip_tags(get_the_term_list( $post->ID, 'status', '', ', ', '' )); ?>" style="text-transform: capitalize"><?php echo strip_tags(get_the_term_list( $post->ID, 'status', '', ', ', '' )); ?></td>-->
    				<td class="<?php echo $status ?>" style="text-transform: capitalize"><?php echo $status ?></td>
                </tr>
    
    		<?php
    	}
    	?>
    	</table>
    	</div>
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }
    ?>
    
Viewing 10 results - 1 through 10 (of 188 total)