Search Results for 'get_field'

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

Viewing 10 results – 171 through 180 (of 219 total)
  • Author
    Search Results
  • #55931

    Anonymous
    Inactive

    So this is kind of similar to a question I’ve already asked. But now I’m struggling with the styling of the echo.

    To echo the checked boxes I use the following code:

    function locaties_search() {
        global $searchandfilter;
        $sf_current_query = $searchandfilter->get(3403)->current_query();
        return $sf_current_query->get_fields_html(array("_sft_locatie"), array('show_all_if_empty' => false));
    }
    
    add_shortcode('locatiesearch', 'locaties_search');

    And then I use the following shortcode to echo the results:
    <?php echo do_shortcode('[locatiesearch]'); ?>

    Right now it’s displaying the results like:
    Location:Location-x, Location-y

    What I would like is to have it just echo like so:
    Location-x
    Location-y

    What code should I use?

    #55304

    Anonymous
    Inactive

    TL;DR (but please read): custom taxonomy values are not being pulled from the post, except for sometimes.

    I have a Custom Post Type: vehicles. I created two custom taxonomies just for that CPT: vehicle_make and vehicle_model. These were done use the CPT UI plugin. There are various other ACF fields as well.

    The search form is setup like so:
    Make | Model | Year | Location | Reset

    You can see the dev version here:
    http://tap.voltaic.xyz/inventory/

    I’m displaying the results using a custom template (600.php):

    <?php if ( $query->have_posts() )
    {
    	?>
    	
    	<div class="inv_container">
    		<p class="inv_count">Found <?php echo $query->found_posts; ?> Vehicles</p>
    		<p class="inv_note">You can bookmark and share these results.</p>
    
    		<div class="inv_header clear">
    			<div class="inv_make">Make</div>
    			<div class="inv_model">Model</div>
    			<div class="inv_year">Year</div>
    			<div class="inv_location">Location</div>
    			<div class="inv_row">Row</div>
    		</div>
    		<?php while ($query->have_posts()) { $query->the_post(); ?>
    			<?php 
    			$classes = array();
    			$classes[] = "inv_item";
    			$classes[] = "clear";
    			?>
    
    			<article <?php post_class($classes); ?> >
    				<div class="inv_make"><?php echo get_field('v_make')->name; ?></div>
    				<div class="inv_model"><?php echo get_field('v_model')->name; ?></div>
    				<div class="inv_year"><?php the_field('year'); ?></div>
    				<div class="inv_location"><?php the_field('city'); ?></div>
    				<div class="inv_row"><?php the_field('row'); ?></div>
    			</article>
    
    		<?php }	?>
    	</div>
    
    	<?php
    }
    else
    {
    	echo "No Results Found";
    }
    ?>

    When you visit the dev site you’ll see that I’m receiving a PHP error because the custom taxonomy values are not being pulled from the post. However, if you look at this custom search you’ll notice that one of the results is showing as intended:
    http://tap.voltaic.xyz/inventory/?_sft_vehicle_make=honda&_sft_vehicle_model=civic&_sfm_year=1999

    I added about 1800 posts to this CPT using WP Ultimate CSV Importer. When I edit one of these posts, from the import, the custom taxonomies show up on the edit screen, selected as they are expected to be (I also imported a sampling of posts using another CSV importer and it had the same results). Now, here’s the interesting part, if I update one of the posts, from the import, it will show up as expected in the results (I just edit the post and immediately click Update, nothing else). The Honda Civic from that custom search is one such post that was updated after the fact. You can imagine that I’m not keen on updating 1800 posts one at a time. Not to mention, I shouldn’t have to.

    I installed a different search/filter plugin (Filter Custom Fields & Taxonomies Light) and it displayed results correctly. Though, I don’t like that plugin for its UX and various other reasons. It doesn’t have any problem pulling the custom taxonomy value from the post. You can see those results pulling from the same CPT here:
    http://tap.voltaic.xyz/test-search/

    I really need a resolution for this issue. I’ve spent at least 8 hours trying various things to resolve it. Please help.

    #52078

    In reply to: Getting value from url


    Trevor
    Participant

    This?

    <?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(15)->current_query();
    	print_r($sf_current_query->get_fields_html(array(), array('show_all_if_empty' => false)));
    ?>
    #52076

    In reply to: Getting value from url


    Trevor
    Participant

    I see the error. My bad for copying and pasting. The forum has changed the quotes 🙁

    <?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(15)->current_query();
    	print_r $sf_current_query->get_fields_html(array(), array('show_all_if_empty' => false));
    ?>

    Or, I hope that is it.

    #52072

    In reply to: Getting value from url


    Anonymous
    Inactive

    If I use this code:

    <?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(15)->current_query();
    	print_r $sf_current_query->get_fields_html(array(), array(‘show_all_if_empty’ => false));
    ?>

    It “breaks” the page…?

    #52071

    In reply to: Getting value from url


    Trevor
    Participant

    I need to see the array structure to know which element to grab. This code instead of the current echo should give the array:

    print_r $sf_current_query->get_fields_html(array(), array(‘show_all_if_empty’ => false));
    
    #51940

    In reply to: Getting value from url


    Anonymous
    Inactive

    <?php echo $sf_current_query->get_fields_html(array("_sft_aantal_personen","_sft_arrangementstype","_sft_type_boot","_sft_type_boot_2","_sft_boot_opties"), array('show_all_if_empty' => false)); ?>

    This…

    #51933

    In reply to: Getting value from url


    Anonymous
    Inactive

    Hi Trevor,

    I think it’s this part:

    <?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(15)->current_query();
    ?> 
    
    <?php $arrangement = $sf_current_query->get_fields_html(array("_sft_aantal_personen","_sft_arrangementstype","_sft_type_boot"), array('show_all_if_empty' => false)); ?>

    I like to keep my echo’s separate from the rest… so I can echo them where ever I like.

    #46642

    Trevor
    Participant

    OK, the get_field('resource_date') part needs to be inside a php function. See here:

    http://php.net/manual/en/datetime.createfromformat.php

    Look at the example#2 towards the bottom.

    Modifying what they have there.

    $resource_date = DateTime::createFromFormat('Ymd', get_field('resource_date'));
    echo '<p class="lol-resource-date">' . $resource_date->format('F j, Y') . '</p>';

    That might even compress down to:

    echo '<p class="lol-resource-date">' . DateTime::createFromFormat('Ymd', get_field('resource_date'))->format('F j, Y') . '</p>';
    
    #46544

    Anonymous
    Inactive

    Yes there is a template file and yes I added code for the ACF field. All the other ACF fields are working normally and pulling in the proper data, just not the date field.

    This is the code for the date field (php tags are also in there):

    echo ‘<p class=”lol-resource-date”>’ . get_field(‘resource_date’) . ‘</p>’;

Viewing 10 results – 171 through 180 (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.