Hi, i had an question. I made an shortcode which displays me locations. I use a meta_value ( ACF field ) to filter. But when i on a page of these locations, this one location should not be displayed. It should be excluded. I tryed the WP argument ‘post__not_in’ => array( $post->ID ) but it dont works.
Here is my code:
function messe_feld( $atts ) {
$veranstalter = get_field('messe_namen_detail');
// Defaults
extract( shortcode_atts( array (
'kategorie' => '',
'veranstalter' => $veranstalter
), $atts ) );
// Parameter
$options = array(
'post_type' => 'messen',
'messe_kategorie' => $kategorie,
'meta_value' => $veranstalter
);
// query
$the_query = new WP_Query( $options );
if( $the_query->have_posts() ):
$return .= '<div class="messe-liste">';
while( $the_query->have_posts() ) : $the_query->the_post();
$return .= '<div class="messe-item">';
$return .= '<div class="messe-header-jail">';
$return .= '<img class="messe-bild" src="/wp-content/themes/wpcasa/img/messe-bild.jpg" alt="Messe Header" />';
$return .= '<img class="messe-logo" src="'.get_field('messe_logo').'" alt="Messe Logo" />';
$return .= '</div>';
$return .= '<div class="messe-datum">'.get_field('messe_datum_beginn').' - '.get_field('messe_datum_ende').'</div>';
$return .= '<div class="messe-title">'.get_field('messe_name').'</div>';
$return .= '<div class="messe-beschreibung">'.get_field('messe_beschreibung').'</div><span class="messe-weiter">Mehr erfahren</span>';
$return .= '<a class="messe-details-link" href="'.get_field('messe_details_link').'"></a>';
$return .= '</div>';
endwhile;
$return .= '</div>';
endif;
wp_reset_postdata();
return $return;
}
add_shortcode( 'messe-feld', 'messe_feld' );
I hope you understand me, sorry for my bad english.
$post->ID
does not have a value inside of your function unless you declare the global
function messe_feld( $atts ) {
global $post;
// ......
The topic ‘Exclude ACF meta_value’ is closed to new replies.
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.