Solution if anyone is look for it, managed to figure it out.
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'is_featured_product',
)
)
);
?>
<?php $loop = new WP_Query( $args ); ?>
<div class="nav subnav">
<ul id="menu-top-ten-product-menu" class="menu">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li>
<a href="<?php the_field('product_logo'); ?>">
<img src="<?php the_field('product_logo'); ?>" alt="">
</a>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
</div>
Of course.
The issue is because of I had changed the value of the choices in a checkbox custom field without I realised I would need update the posts. Now, I’ve many posts with the old value and many others with the new one. This is a problem in searching, but besides, its a problem when is need to edit one posts because the old value selected it doesn’t appears and the update isn’t done because can’t validate ( it’s an required field)
Now I need to verify the value in each post, and update it. I was looking for another solution, may be updating de databse from the plugin.
Thanks a lot
Hi @elliot!
It’s me once again. The simple solution would be the one displayed here
So the following would work for me:
echo ‘flush_all’ | nc localhost 11211
or in PHP something like this:
if ( file_exists( WP_CONTENT_DIR . ‘/object-cache.php’ ) &&
$fp = fsockopen(“localhost”, 11211, $errno, $errstr, 30) ) {
fwrite($fp, “flush_all\r\n”);
$output = ”;
while (!feof($fp))
$output .= fgets($fp, 128);
// do whatever you want with $output… what you should get is “OK”
fclose($fp);
}
Cheers
Günther
Thanks.
I though it would tell me in the WP admin that I needed to update (I checked there before asking the question).
I’ll know for the future that I need to check here for the last version everytime I use it…
Hi @moralejf
The ‘home page’ or ‘blog page’ does not have a global $post object becuase the query is to load the posts.
This means that a get_field call won’t work because ACF doesn’t know which page to load from.
A solution for this is to check if the page is_home:
http://support.advancedcustomfields.com/forums/topic/acf-fields-not-displaying-on-posts-page/
Hi @jhayunu
Thanks for the question. This kind of query has not yet been attempted here, so you will be the first to undertake the task!
Please first read the documentation for querying sub field values:
http://www.advancedcustomfields.com/resources/tutorials/querying-the-database-for-repeater-sub-field-values/
You will need to write some custom SQL to compare between the values, but I’m not entirely sure this can work with a ‘LIKE’ on the meta_name…
Good luck, but this is far beyond the scope of the plugin and I can’t offer too much free support for this one.
Cheers
E
Hi @jaypeg
Yes, you can use the relationship field in this way. Does that answer your query?
Perhaps you would be interested in using the repeater field + image sub field instead?
Thanks
E
Please use this filter to modify the WP_Query args:
http://www.advancedcustomfields.com/resources/filters/acf-fields-relationship-query/
Thanks
E
Hi @hungrysquirrel,
Sorry! you’re right, the syntax above was incorrect. I’m glad it got you on the right track though.
Did you get it working?
Cheers
Oh wait this might be working…I am new to PHP….
notice the instances of “$currMonth != $date->format(‘F’)”, I imagine this makes the function return a string, is that right?
<?php
$repeater = get_field('race_event');
foreach( $repeater as $key => $row )
{
$column_id[ $key ] = $row['race_date'];
}
array_multisort( $column_id, SORT_ASC, $repeater );
$currMonth = "start";
foreach( $repeater as $row ) :
{
$date = DateTime::createFromFormat('Ymd', $row['race_date']);
$website_url = $row['race_website'];
if ($currMonth != $date->format('F')) :
{
echo '<h2>' . $date->format('F') . '</h2><br>';
$currMonth = $date->format('F');
}
endif;
echo '<ul>';
echo '<li><h2>' . $row['race_name'] . '</h2></li>';
echo '<li>Date ' . $date->format('F d, Y') . '</li>';
echo '<li>Distance ' . $row['race_distance'] . '</li>';
echo '<li>Vertical ' . $row['race_vertical'] . '</li>';
echo '<li>URL <a href=' . $website_url . '> ' . $website_url . ' </a></li>';
echo '<li>' . $row['race_description'] . '</li>';
echo '</ul>';
}
endforeach;
?>
I think this is on the right track but I am getting this error.
Did I miss something in your example?
Fatal error: Function name must be a string
this is my code
<?php
$repeater = get_field('race_event');
foreach( $repeater as $key => $row )
{
$column_id[ $key ] = $row['race_date'];
}
array_multisort( $column_id, SORT_ASC, $repeater );
$currMonth = "start";
foreach( $repeater as $row ) :
{
$date = DateTime::createFromFormat('Ymd', $row['race_date']);
$website_url = $row['race_website'];
if ($currMonth != $date('F')) :
{
echo '<h2>' . $date('F') . '</h2><br>';
$currMonth = $date('F');
}
endif;
echo '<ul>';
echo '<li><h2>' . $row['race_name'] . '</h2></li>';
echo '<li>Date ' . $date->format('F d, Y') . '</li>';
echo '<li>Distance ' . $row['race_distance'] . '</li>';
echo '<li>Vertical ' . $row['race_vertical'] . '</li>';
echo '<li>URL <a href=' . $website_url . '> ' . $website_url . ' </a></li>';
echo '<li>' . $row['race_description'] . '</li>';
echo '</ul>';
}
endforeach;
?>
Hi @hungrysquirrel,
Something like this?
$currMonth = "start"
foreach( $repeater as $row ) :
{
$date = DateTime::createFromFormat('Ymd', $row['race_date']);
if(currMonth != $date->format('F'))
echo '<h2>' . $date->format('F') . '</h2><br>';
$currMonth = $date->format('F');
endif
echo '<li>' . $row['race_name'] . '</li>';
echo '<li>' . $date->format('m-d-Y') . '</li>';
}
endforeach;
Thanks for the quick response! Though passing the page’s post ID as a parameter did in fact make get_fields() behave accordingly by fetching the page’s custom fields, the page’s behavior is still very, very weird. For instance when I output the Array that get_fields() fetches, everything looks normal I get an array that looks like this:
array(3) {
["jumbo_1"]=>
string(96) "http://localhost:8888/juanturcios.com/wp-content/uploads/2014/01/father-and-son-juan-turcios.jpg"
["jumbo_2"]=>
string(101) "http://localhost:8888/juanturcios.com/wp-content/uploads/2014/01/fashion-photography-juan-turcios.jpg"
["jumbo_3"]=>
string(96) "http://localhost:8888/juanturcios.com/wp-content/uploads/2014/01/wedding-brides-green-forest.jpg"
}
That means get_fields() is working properly. HOWEVER, when I go in and key into this array randomly (and again, the same code works in all pages except my blog index listing page home.php) and use the code’s output to generate the link for the banner’s background image, it is blank. Upon inspecting the div I can see that the background: url(”); is in fact blank. So then I decided to instead try to code it manually and used intead the function the_field(‘jumbo_1’) passing it the first image’s field name key so it would maybe display and nothing happened– still blank. Puzzled by this I decided to pass in the field name of a custom field that is available ONLY for single.php blog posts: the_field(‘slider_image_1’); which enables the user to upload an image for an image slider on every blog post. And to my surprise it did show up!
It’s so odd. It seems as if the blog listing page did not have access to its own custom fields (despite the fact that get_fields() is outputting the right field group array) and rather somehow the code can display fields that are not even allowed to be on the blog page.
Any insights on this? Should I change my field location rule logic somehow?
My code is sorting.
My question may not have been clear, sorry.
Is there a way to do grouping within the sorting so all the entries for May are in a group with the “May” heading and all the June dated custom fields are in the “June” grouping?
If so could you give me some tips on how to implement that with my code above?
Hi @WPDragon
This is called a conditional statement:
<?php
$url = get_field('photographer_url');
?>
<p class="image_photographer">Image courtesy of: <?php if( $url ): ?><a href="<?php echo $url; ?>"><?php endif; ?> <?php the_field('image_photographer') ?> <?php if( $url ): ?></a><?php endif; ?></p>
Hi @lowercase
If you are viewing the post of ‘Metallica’, then the current post id can be found like so:
$post_id = get_the_ID();
This is the value you should use to query the posts with!
Change ‘Melbourne’ to $post_id
Thanks
E
Hi @cmegown
You can render the data corerectly like so:
<?php
$products = get_field( 'products' );
$products = array_map('sanitize_title', $products);
$products = implode(' ', $products );
?>
<li class="<?php echo $products; ?>"></li>
Links:
http://codex.wordpress.org/Function_Reference/sanitize_title
http://au2.php.net/array_map
Thank you for your quick response – I will try those methods – and thanks again for making such an awesome plug in!
Hi @chandru998
The above code that I wrote has 0% connection to the WP_Query object. This means you cant modify it via the query code you have above.
You will need to use the code that I wrote above.
Thanks
E
Hi @matoma16
Sub field required validation was added in v1.1.0 of the repeater field. Can you please update your repeater field add-on?
Thanks
E
Hi @cyberwani
Not at all, you can include ACF4 in your theme without any premium add-ons and no license is required.
Thanks
E
Close, but change:
the_post_thumbnail( '$size' );
to
the_post_thumbnail( $size );
Please be aware, that you have placed the $size = get_field('image_size');
OUTSIDE of your $myposts loop, so this value is not coming from the post itself, but from what ever the template file is querying.
Thanks
E
Is your above code working? Are you sorting successfully?
To link to different parts on the page, you can use an anchor tag using a name attribute and #target. Read more here
http://www.echoecho.com/htmllinks08.htm
Thanks
E
Hi @realph
Thanks for the question, it is very clear to see what you are attempting to do.
The above will not be easy, but it is not impossible. Lets start with filtering the products that are ‘blue’.
You can use this tutorial here to query sub field values:
http://www.advancedcustomfields.com/resources/tutorials/querying-the-database-for-repeater-sub-field-values/
This tutorial may seem a bit complex, but your task here is to find all the $rows in the postmeta table, where ‘blue’ was selected.
Withing the $rows
loop, you can find the post_id like so $post_id = $row->post_id
;
This allows to get the product ID that contains this ‘blue’ color. Instead of assigning this to a variable called $post_id
, you should append it to an array like so: $ids[] = $row->post_id
;
After your loop is complete, you should have a populated $ids array which you can now use in a WP_Query argument in the ‘posts__in’ arg!
To show the blue image as the featured one, just loop through all the repeater rows and then match the ‘product_colour’ value to the current queried color. When a match is found, display that image!
Thanks
E
Hi @elliot — This was solved, but just had one quick question related to this…The code above is working perfectly, but I noticed if I put the Photographers Name, without a URL — the Photographers Name will still be a hyperlink & it will reopen the same post page its on…Is there a way, that if I do not include a URL, that it will only display the Photographer name as plain text, and not as a hyperlink?
Hope that makes sense. thanks.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.