Search Results for 'get_field'

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

Viewing 10 results – 181 through 190 (of 219 total)
  • Author
    Search Results
  • #45816

    Anonymous
    Inactive

    hi,
    i’m using the Accessing the Search Data instructions to display the search terms in the heading.
    everything is working fine. the only problem is i can’t seem to find a way to remove the label and display only the search term alone.
    i’m using the echo $sf_current_query->get_field_string function

    would really appreciate help on this issue.

    thanks, eli.

    #45533

    Anonymous
    Inactive

    I am trying to create a listing of resource documents using a custom post type and custom fields. However, my custom fields are not displaying properly when using Search & Filter.

    My set-up is this:
    – using custom Genesis child theme
    – custom post type registered in functions.php (if I get the search working I will move the code to a plugin)
    – custom fields created using Advanced Custom Fields
    – custom posts created and published using the custom fields only (no native WP edit field)
    – new page “Resources” published with a custom template coded to display custom fields and S&F search form; tested and displaying fine
    – S&F Pro installed and configured (with Relevanssi enabled for custom field indexing).
    – search form is just a basic keyword search field while testing
    – Ajax disabled
    – force is_search enabled

    My goal is to display all available documents on initial page load. Then the user would enter a search term and the form would return relevant results on the same page and in the same container as before. (This is pretty much the same set-up as in the “Movie” demo used on the S&F demo page.)

    Before enabling Relevanssi, the search was returning relevant results (when configured as a Post Type Archive – ) but only with the native WP post title, not any of the custom fields. When I switch configuration to Custom or Using Shortcode, I get a “hasn’t been configured to use shortcodes” message. My shortcodes (both when necessary) are definitely in the template used to display the page.

    After enabling Relevanssi, I get another error message “attempt to assign property of non-object…” when configured as Post Type Archive or Using Shortcodes.

    I suspect the problem lies in the custom loop I am using on the template file. Problem is, I have no idea how to modify this custom loop to make it work AND still query my custom post type. All Google searches lead me to how to customize the loop with WP_Query (which it already is using) or other versions that apparently S&F doesn’t like.

    So my question is… could this be my issue and, if so, how do I modify the basic WP loop to query a custom post type in a manner that S&F can work with?

    Or put another way…. how can I make this: http://demo.designsandcode.com/sfpro-movie-reviews/

    ANy help and suggestions would be most appreciated. I have hit a brick wall and exhausted my limited PHP knowledge.

    This is the code in my template file that is used for the “Resources” page:

    <?php
    
    function lol_resources_custom_fields() {
    
    ?>
    	<div class="two-thirds first">
    	 <div id="resource-results">
    
    <?php
    
      $args = array(
        'post_type' => 'resources',
        'post_status' => 'publish',
        'posts_per_page' => '10'
      );
    
      $resources_loop = new WP_Query( $args );
      if ( $resources_loop->have_posts() ) :
        while ( $resources_loop->have_posts() ) : $resources_loop->the_post();
          
      	echo '<h4>' . get_field('resource_title') . '</h4>';
    		echo '<p>' . get_field('resource_description') . '</p>';
    		echo '<p>' . get_field('resource_type') . '</p>';
          	
        endwhile;
        wp_reset_postdata();
       endif;
    
      		echo do_shortcode('[searchandfilter id="456" show="results"]');
        ?>		
      		</div>  <!-- end #resource-results -->
    		</div>  <!-- end .two-thirds -->
    
    		<div class="one-third">
    		  <div id="resource-form">
    		    <?php echo do_shortcode('[searchandfilter id="456"]'); ?>
    		  </div>  <!-- end #resource-form -->
    		</div>  <!-- end .one-third -->
    
    	<?php
    }
    
    #45212

    Anonymous
    Inactive

    No problem – speedy recovery.

    I think the problem lies with the code I have customized here for results.php in SFpro. It seems that maybe my conditional for the second part doesn’t take into consideration the arguments of the query. I end up with all the posts in my db generating equivalent modals. :

    <?php
    /**
     * Search & Filter Pro
     *
     * Sample Results Template
     *
     * @package   Search_Filter
     * @author    Ross Morsali
     * @link      http://www.designsandcode.com/
     * @copyright 2015 Designs & Code
     *
     * Note: these templates are not full page templates, rather
     * just an encaspulation of the your results loop which should
     * be inserted in to other pages by using a shortcode - think
     * of it as a template part
     *
     * This template is an absolute base example showing you what
     * you can do, for more customisation see the WordPress docs
     * and using template tags -
     *
     * http://codex.wordpress.org/Template_Tags
     *
     */
    
    // $term_list = wp_get_post_terms($post->ID, 'product_features', array("fields" => "all"));
    // foreach($term_list as $term_single) {
    // echo $term_single->slug; //do something here
    // }
    
    if ( $query->have_posts() )
    {
    	?>
    
    	<div class="">
    
    	<?php
    	while ($query->have_posts())
    	{
    		$query->the_post();
    
    		?>
    
    			<a class="col-md-6 col-lg-4 col-sm-6">
    				<article class="module-container eModal-post-<?php the_ID();?>" href="<?php the_permalink();?>">
    
    				    <h3><?php the_title();?></h3>
    
    				</article>
    			</a>
    
    			<?php
    
    			if( get_field( "demo_module" )) {
    
    			echo do_shortcode( "[modal id='post-". get_the_ID() ."' size='large' title='". get_the_title() ."']".
    
    				 "<div class='col-md-8'>"  . get_the_content() .  "<div class='demo-module'>" . "<a class='cta-button-v4' href='" . get_field( "demo_module" ) . "' target='_blank'>Download Demo Module</a>". "</div>" .  "</div>" . "<div class='col-md-4'>" . do_shortcode("[module_author]") . "</div> <div class='col-md-12'><div class='cta-module'>" . do_shortcode("[cta_module_shortcode]") . "</div></div>" .
    
    				 do_shortcode("[wpdm_package id='". get_the_ID() . "']").  "[/modal]" );
    
    			 } else {
    
    				 echo do_shortcode( "[modal id='post-". get_the_ID() ."' size='large' title='". get_the_title() ."']".
    
    	 				 "<div class='col-md-8'>"  . get_the_content() .   "</div>" . "<div class='col-md-4'>" . do_shortcode("[module_author]") . "</div> <div class='col-md-12'><div class='cta-module'>" . do_shortcode("[cta_module_shortcode]") . "</div></div>" .
    
    	 				 do_shortcode("[wpdm_package id='". get_the_ID() . "']").  "[/modal]" );
    
    			 }
    
    				 ?>
    
    		<?php
    	}
    	?>
    
    	</div>
    
    	<?php
    }
    else
    {
    	echo "No Such Modules";
    }
    ?>
    

    Trevor
    Participant

    So, to use this plugin, in WP Admin go to Settings -> Post Snippets

    Click Add New Snippet

    In the title, give it a shortcode name (must be a valid WP slug name), for example:

    my-color-link

    Check the Shortcode and PHP Code checkboxes.

    In the Snippet textarea copy and paste this:

    $livit_kategorie = get_field('Kategorie');
    $livit_barva = get_field('barva');
    $livit_url = get_site_url() . '/fotogalerie-vysledky/';
    echo '<strong><span style="color: #c62daa;">Kategorie</span></strong>: <a href="';
    echo $livit_url;
    echo '?_sfm_Kategorie=';
    echo $livit_kategorie;
    echo '">';
    echo $livit_kategorie;
    echo '</a><br /><strong><span style="color: #c62daa;">Barva</span></strong>: <a href="';
    echo $livit_url;
    echo '?_sfm_barva=';
    echo $livit_barva;
    echo '">';
    echo $livit_barva;
    echo '</a>';

    There may be errors in that 😉 as I cannot test it here.

    Now all you do is place that shortcode where you want those two lines:

    [my-color-link]


    Anonymous
    Inactive

    Hi Trevor,

    No, those fields are stored as metadata attached to the ‘resort’ CPT, not post ID’s.

    I can query that data easily enough elsewhere on the site and display it, for example on any specific Deal, I can show the resort metadata by either using ACF’s “get_field” or “the_field” but I generally use the stock WP “get_post_meta($post->ID,’metakey’,true)”.

    #43630

    Anonymous
    Inactive

    Thanks for this code, I had to adjust the code to add extra closing brackets for the STRING (below), unfortunately this results in the same data being given.

    “Yacht Length: 40-50m”

    <?php
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query();
    echo $sf_current_query->get_field_string(“_sft_length”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_rate”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_guest”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_location”, array(“str” => “%2$s”));
    echo $sf_current_query->get_field_string(“_sft_toy”, array(“str” => “%2$s”));
    ?>

    #43625

    Trevor
    Participant

    Hi, can you try this code (it might be a step backwards, but bear with me):

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query();
    echo $sf_current_query->get_field_string("_sft_length", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_rate", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_guest", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_location", array("str" => "%2$s");
    echo $sf_current_query->get_field_string("_sft_toy", array("str" => "%2$s");
    #43567

    Trevor
    Participant

    Try this (BTW, please use the code tags in the editor toolbar to enclose code 🙂 ):

    get_fields_html(array("_sft_length", "_sft_rate", "_sft_guest", "_sft_location", "_sft_toy"), array('show_all_if_empty' => false));
    
    #43565

    Anonymous
    Inactive

    Hi,

    I’ve added the code but it seems to be throwing an error on the array. Am I missing something?
    <?php
    //Get a multiple fields values by passing an array of field names
    //replace 1526 with the ID of your search form
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(339)->current_query();
    echo $sf_current_query->get_fields_html(array(), array(‘show_all_if_empty’ => false)
    );
    ?>

    I’ve also added the code from the supplied link but it throws back the following error:
    array(2) { [“_sft_length”]=> array(5) { [“name”]=> string(13) “Yacht Lengths” [“singular_name”]=> string(12) “Yacht Length” [“all_items_label”]=> string(17) “All Yacht Lengths” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(6) [“name”]=> string(6) “40-50m” [“value”]=> string(6) “40-50m” [“count”]=> int(5) } } } [“_sft_toy”]=> array(5) { [“name”]=> string(15) “Yacht Hero Toys” [“singular_name”]=> string(14) “Yacht Hero Toy” [“all_items_label”]=> string(19) “All Yacht Hero Toys” [“type”]=> string(8) “taxonomy” [“active_terms”]=> array(1) { [0]=> array(4) { [“id”]=> int(16) [“name”]=> string(7) “Freezer” [“value”]=> string(7) “freezer” [“count”]=> int(5) } } } }

    Found on the same web link as before.

    #43562

    Trevor
    Participant

    Hi

    Ross tells me that there is additional functionality on this filter, he says this will be useful to you:

    get_fields_html(array(), array('show_all_if_empty' => false))
    

    Instead of what you used. As to the other x link feature, he says it is not there now, but is coming (as is an easier way to what you have above), but this may be useful to you:

    http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/#Getan_array_offilterswithvalues_and_labels

Viewing 10 results – 181 through 190 (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.