Yes that works, thank you
if( have_rows('home_page_intro') ):
while ( have_rows('home_page_intro') ) : the_row();
get_template_part( 'components/clones/split-col');
endwhile;
endif;
OK, so using a newer version of 5.8 (5.8.0-beta4) resulted in the “Blocks” item showing in the location menu, and this way of adding the function for the child theme ensures the block shows up in the list:
if ( ! function_exists( 'acf_register_block' ) ) {
add_action('acf/init', 'register_acf_blocks');
}
Thank you. For sure there’s workarounds, but I spent a fair bit of time trying to figure out why my post screens were broken, so a permanent solution would be nice, as others might experience a similar issue.
OK so this was actually due to a conflict with the Posts Types Order plugin, the query works as expected.
Thanks @gummiforweb
You’re correct, when a post has been checked and un-checked as a “featured post” it is excluded from the loop, never to be seen again.
Your code solves this problem – thanks.
Thank you
Using 'compare' => 'NOT EXISTS'
instead of 'compare' => '!='
seems to return all posts and exclude the meta_query.
function exclude_featured_post( $query ) {
if ( $query->is_home() && $query->is_main_query()) {
// in case for some reason there's already a meta query set from other plugin
$meta_query = $query->get('meta_query')? : [];
// append yours
$meta_query[] = [
'key' => 'featured_post',
'value' => '1',
'compare' => 'NOT EXISTS'
];
$query->set('meta_query', $meta_query);
//echo '<pre>'; print_r( $query ); echo '</pre>';
}
}
add_action( 'pre_get_posts', 'exclude_featured_post' );
From here: https://core.trac.wordpress.org/ticket/18158
Thanks @gummiforweb
I can’t get the query to return any posts.
This will get the posts with the ACF True/False set to 1:
$meta_query[] = [
'key' => 'featured_post',
'value' => '1',
'compare' => '='
];
However this will not do the opposite, and exclude the posts, it shows nothing:
$meta_query[] = [
'key' => 'featured_post',
'value' => '1',
'compare' => '!='
];
Trying things like 'value' => ''
with 'compare' => '='
also returns nothing.
Thanks for all your help James, I got it working using get_the_term_list
, like so:
$terms = get_the_term_list( $post->ID, 'key_tasks', '', ',' ); $terms = strip_tags( $terms );
if ($terms) {
echo '<p>'.$terms.'</p>';
} else {
}
Thanks for the continued explorations into this, it’s much appreciated. Field group export attached.
Thanks.
Thanks James
To confirm, the terms are being saved, see here:
When using this example – https://www.advancedcustomfields.com/resources/taxonomy/ – like so:
<?php
$terms = get_field('key_tasks_list');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<?php
echo '<pre>';
var_dump( $terms );
echo '</pre>';
endforeach; ?>
</ul>
<?php endif; ?>
I get NULL returned.
Thanks
Thanks James.
I’m afraid I omitted the while loop from my original example code, I am in fact using the same as yours – this:
while( $query_clients->have_posts() ) { $query_clients->the_post();
Here’s my full code:
$client_args = array (
'post_type' => array( 'clients' ),
);
$query_clients = new WP_Query( $client_args );
if ( $query_clients->have_posts() ) {
while ( $query_clients->have_posts() ) {
$query_clients->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php
// Key Tasks
// --------------------
$terms = wp_get_object_terms( $post->ID, 'key_tasks' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
echo '<p class="item-text">' .$term->name. '</p>';
}
}
echo '<pre>';
var_dump( $terms );
echo '</pre>';
<?php } ?>
<?php } else {
// no posts found
}
wp_reset_postdata();
Also keen to add a custom image within the Elements list – any ideas?
Thanks
Thanks, that makes sense.
Thank you.
I’ve got this into a position I need, so thanks, but for the sake of this thread being useful, I should say that this:
$job_term = get_term(get_field('member_person_job'), 'jobs');
echo $job_term;
Results in this error on the archive page:
Thank you.
Using this:
$job_term = get_term(get_field('member_person_job'), 'taxonomy-name');
echo $job_term;
Produces this error:
However, I can get the term using this:
$job_term = get_the_term_list( $post->ID, 'jobs', '', ',' ); $terms = strip_tags( $terms );
Based on your comment, the original block used on taxonomy-jobs.php should work, but this still results in NULL:
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$job_title = get_field('member_person_job', $taxonomy . '_' . $term_id);
echo $job_title;
By all accounts this should work on the taxonomy page?
OK that makes some sense.
So if I have it set to return the ID, how do I then get the term, currently it outputs the ID number via the echo, so presumably I’d need something like:
echo $job_title->term_id;
But then I’m back to using this block:
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
Which produces the errors.
It’s a Post Type, see here: http://cl.ly/1w2J1z3B3R2R
I can confirm the same error message appearing with a Relationship field, and changing the variable to something other than $posts does fix the issue.
Thanks Elliot, my echo wasn’t correct, your ‘<?php echo $specialtopic->name; ?>’ fixes the problem just as I’d like.
Many thanks for your time looking at this, and the fix.
Thanks
Dave
Perfect – did just what I wanted. Thanks Elliot.
This combination output the label correctly, thanks for the pointers.
<?php
/*
* Displaying a single value's Label
*/
$field = get_field_object('color');
$value = get_field('color');
$label = $field['choices'][ $value ];
?>
Another question on the same issue has raised though. I have a page, with a colorscheme set as described above, also within the page, I have a Repeater Field, which has a sub-field to set a colorscheme.
I’d like to use the same set of color options I’ve set in Options. This works fine if the sub field is named “color”, as this will pick up the choices for a select list. But when these are output, things get confused between the pages colorcheme, and the repeater field box colorscheme – both of which come from a field called “color”.
Is it possible to have a page and a repeater field using the same Options data source for a select list?
Thanks.
Thanks Elliot. Further bit of testing, from this code block:
<?php // Color scheme
// --------------------------------------------------------------------------------
// Grab the color scheme for pages. Sub pages inherit the parent's color scheme.
// http://wordpress.org/support/topic/plugin-advanced-custom-fields-field-from-parent-page-into-child-page
global $post;
// Get parent ID
$parent_id = $post->post_parent;
// Parent color
$color_scheme_parent = get_field('color', $parent_id);
?>
<?php
/*
* Displaying a single value's Label
*/
$field = get_field_object('color_scheme_color');
$value = get_field('color');
$label = $field['choices'][ $value ];
?>
Color field: <?php echo $field; ?> <br>
Color value: <?php echo $value; ?> <br>
Color label: <?php echo $label; ?> <br>
Parent color: <?php echo $color_scheme_parent; ?>
I get this output on the page (page.php):
Color field: Array
Color value: #464972
Color label:
Parent color: #464972
Do you have any other de-bugging suggestions or tests I could perform to see why I can’t output the label?
Many thanks!
Thanks for this.
I’m still outputting nothing for the label though. With this block of code, I can happily output the $color_scheme_parent variable, which is the value set from the select list, but not the label:
<?php
/*
* Displaying a single value's Label
*/
$field = get_field_object('color');
$value = get_field('color_scheme_color');
$label = $field['choices'][ $value ];
?>
<p>Color label: <?php echo $label; ?> Parent color: <?php echo $color_scheme_parent; ?></p>
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.