Where you added code – category.php ?
Please test:
print_r($color);
var_dump($color);
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
Please check my settings https://d.pr/FREE/CIhgG4
<?php
$colour = get_field('menu_colour');
if( !$colour ) {
$colour = 'default';
}
?>
<nav id="desk" class="<?php echo $colour; ?>">
</nav>
Display only selected items:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'DSC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'exclude_post',
'value' => '1',
'compare' => '=',
),
array(
'key' => 'exclude_post',
'compare' => 'EXISTS',
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) :
$query->the_post();
echo '<br/>';
the_title();
endwhile;
wp_reset_postdata();
endif; ?>
Hide selected items:
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'DSC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'exclude_post',
'value' => '0',
'compare' => '=',
),
array(
'key' => 'exclude_post',
'compare' => 'NOT EXISTS',
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) :
$query->the_post();
echo '<br/>';
the_title();
endwhile;
wp_reset_postdata();
endif; ?>
Sorry, I added message to another window.
Soon I’ll help you.
Fix
// Before
'order' => DSC,
// After
'order' => 'DSC',
Hey,
This not work for the NULL case.
You can use var_dump(get_field( 'exclude_post' ));
to test.
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'exclude_post',
'value' => '0',
'compare' => '='
),
array(
'key' => 'exclude_post',
'compare' => 'NOT EXISTS'
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) :
$query->the_post();
the_title();
endwhile;
wp_reset_postdata();
endif; ?>
OK, I found solution.
I used is_admin() function and this cause a problem.
// Before
if ( is_admin() ) {
require_once get_template_directory() . '/core/custom-fields.php';
}
// After
require_once get_template_directory() . '/core/custom-fields.php';
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’re reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.