Buenos dias,
He creado un tipo de publicación personalizada – Productos – y para ese tipo de publicación personalizada he creado un campo personalizado – producto_presentado – usando el complemento de campo personalizado avanzado. Cuando creé el campo personalizado, lo hice usando el tipo de campo Verdadero/Falso.
Estoy tratando de mostrar SOLO aquellas publicaciones de Productos donde está marcada la casilla de verificación de producto_presentado.
Este es mi código actual:
<?php query_posts(array(
'posts_per_page' => 3,
'post_type' => 'products',
'orderby' => 'post_date',
'paged' => $paged
)
); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php if(get_field('featured_product')){ ?>
<div id="post-<?php the_ID(); ?>" class="cpt">
<h2><?php the_title(); ?></h2>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('excerpt');
}
?>
<?php the_excerpt(); ?>
<ul class="prod_detail">
<li><a href="https://stackoverflow.com/questions/11776687/<?php the_field("product_detail_page'); ?>">Learn More</a></li>
<li><a href="https://stackoverflow.com/questions/11776687/<?php the_field("purchase_link'); ?>">Place Order</a></li>
</ul>
</div>
<?php } ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
El problema es que solo devuelve una publicación, pero tengo 3 publicaciones marcadas como destacadas.
¿Qué estoy haciendo mal aquí?
¡Muchas gracias!
Me lo imaginé 🙂
<?php query_posts(array(
'posts_per_page' => 3,
'post_type' => 'products',
'orderby' => 'post_date',
'meta_key' => 'featured_product', // the name of the custom field
'meta_compare' => '=', // the comparison (e.g. equals, does not equal, etc...)
'meta_value' => 1, // the value to which the custom field is compared. In my case, 'featured_product' was a true/false checkbox. If you had a custom field called 'color' and wanted to show only those blue items, then the meta_value would be 'blue'
'paged' => $paged
)
); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="cpt">
<h2><?php the_title(); ?></h2>
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail('excerpt');
}
?>
<?php the_excerpt(); ?>
<ul class="prod_detail">
<li><a href="https://stackoverflow.com/questions/11776687/<?php the_field("product_detail_page'); ?>" target="_blank">Learn More</a></li>
<li><a href="https://stackoverflow.com/questions/11776687/<?php the_field("purchase_link'); ?>" target="blank">Place Order</a></li>
</ul>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
¿Ha sido útil esta solución?
Tu feedback nos ayuda a saber si la solución es correcta y está funcionando. De esta manera podemos revisar y corregir el contenido.