Home › Forums › General Issues › show acf if certain value
Hey Community,
i have an post-type = “3d_drucker” and a custom-field = “sls”.
I would like to list the printers belonging to this type.
I have an ACF (printer_type).
If “sls” is now entered here, then these should be output separately.
<?php
$args = array(
'post_type' => '3d_drucker',
'posts_per_page' => '10',
'orderby' => 'title',
'order' => 'ASC',
);
$Vergleichstabelle = new WP_Query($args);
if($Vergleichstabelle->have_posts()) : while($Vergleichstabelle->have_posts()) : $Vergleichstabelle->the_post();
?>
<?php
if( get_field('printer_type') == 'SLS' ) {
// Do something.
}
// Wenn mindestens 1 Datensatz vorhanden ist
// Platzierung aus Feld laden
$modell = get_field( 'modell' );
// 3D Drucker aus Feld laden
$hersteller = get_field( 'hersteller' );
// 3D Drucker Link aus Feld laden
$image = get_field( 'image' );
// Listenpreis aus Feld laden
$aktionspreis = get_field( 'aktionspreis' );
// Amazon Image aus Feld laden
$amazon_link = get_field( 'amazon_link' );
// Amazon ALT Image aus Feld laden
$amazon_alt_image = get_field( 'amazon_alt_image' );
echo
<div class="row">
<div class="col-lg-4">
<div class="thumbnail thumbnail-9876 product-grid" style="height:507px">
<div class="caption">
<div class="img-grid-wrapper">
<a title="$hersteller - $modell" href="https://dein-3d.com/3d_drucker/$modell">
<img src="$image" alt="$hersteller - $modell" />
<noscript><img src="$image" />
</a>
</div>
<a href="https://dein-3d.com/3d_drucker/$modell">$hersteller - $modell</a>
<div class="product-price">
<p class="price">
<small>ab</small>
$aktionspreis
</p>
<small class="price-hint">inkl. 16% gesetzlicher MwSt.</small>
</div>
<hr class="hidden-xs">
<a href="https://dein-3d.com/3d_drucker/$modell" title="$hersteller - $modell">Details</a>
<a href="$amazon_link" title="$hersteller - $modell" rel="nofollow" target="_blank">Kaufen*</a>
</div>
</div>
</div>
</div>
?>
<?php endwhile; endif; wp_reset_postdata(); ?>
Sounds like you need to query the posts by custom field, as explained at https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters (and do a separate query for posts NOT containing the custom field value, or whatever).
Yes that’s right. But it doesn’t work …
with what needs to be heard here?
<?php
$ad_args = array(
'post_type' => '3d_drucker',
'orderby' => 'rand',
'meta_query' => array(
array(
'key' => '3ddruck-verfahren',
'value' => 'SLS',
)
)
);
// query
$ad_query = new WP_Query($ad_args);
?>
Shouldn’t it rather be
$ad_args = array(
'post_type' => '3d_drucker',
'orderby' => 'rand',
'meta_query' => array(
array(
'key' => 'printer_type',
'value' => 'SLS',
)
)
);
(i. e. different key)
Check the field name/slug that you want to query.
You must be logged in to reply to this topic.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 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.