admin管理员组文章数量:1130349
Before I start, I have to say that I have tried to solve my problem in a thousand different ways and I have read several posts without success.
I have a CPT called "grouped", a taxonomy for that CPT called "orders" and within the WordPress panel I have created several "categories" within orders (terms).
I have a term called "Madrid", and I want to show the post of that term on a page-template. How can I do it? It is killing me literally.
I appreciate your help.
-- This is the loop and the code I used in a normal "taxonomy-template.php" and its work fine, but now I need to show the same information but only showing the post associated with the term "Madrid" in a page template.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php endwhile; endif; ?>
Before I start, I have to say that I have tried to solve my problem in a thousand different ways and I have read several posts without success.
I have a CPT called "grouped", a taxonomy for that CPT called "orders" and within the WordPress panel I have created several "categories" within orders (terms).
I have a term called "Madrid", and I want to show the post of that term on a page-template. How can I do it? It is killing me literally.
I appreciate your help.
-- This is the loop and the code I used in a normal "taxonomy-template.php" and its work fine, but now I need to show the same information but only showing the post associated with the term "Madrid" in a page template.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php endwhile; endif; ?>
Share
Improve this question
edited Dec 3, 2018 at 11:15
Krzysiek Dróżdż
25.6k9 gold badges53 silver badges74 bronze badges
asked Dec 2, 2018 at 20:49
ctrljctrlj
112 bronze badges
2
|
2 Answers
Reset to default 0I found the solution by myself, I leave it here in case someone is interested:
<?php $args = array(
'post_type' => 'agrupados',
'tax_query' => array(
array(
'taxonomy' => 'pedidos',
'field' => 'slug',
'terms' => 'ferrol',
),
),); $the_query_slide = new WP_Query( $args ); if ( $the_query_slide->have_posts() ) {while ( $the_query_slide->have_posts() ) {$the_query_slide->the_post();?>
<?php
/* variables para cada imagen */
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php }} wp_reset_postdata(); ?>
In your code you print posts based on global $wp_query object. If you want to print some posts on another template, not using global query, then you'll have to create your custom query object:
<?php
$groupped = new WP_Query( array(
'post_type' => 'grouped',
'tax_query' => array(
array(
'taxonomy' => 'orders',
'field' => 'slug',
'terms' => 'madrid',
),
),
) );
while ( $groupped->have_posts() ) :
$groupped->the_post();
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php endwhile; wp_reset_postdata(); ?>
Before I start, I have to say that I have tried to solve my problem in a thousand different ways and I have read several posts without success.
I have a CPT called "grouped", a taxonomy for that CPT called "orders" and within the WordPress panel I have created several "categories" within orders (terms).
I have a term called "Madrid", and I want to show the post of that term on a page-template. How can I do it? It is killing me literally.
I appreciate your help.
-- This is the loop and the code I used in a normal "taxonomy-template.php" and its work fine, but now I need to show the same information but only showing the post associated with the term "Madrid" in a page template.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php endwhile; endif; ?>
Before I start, I have to say that I have tried to solve my problem in a thousand different ways and I have read several posts without success.
I have a CPT called "grouped", a taxonomy for that CPT called "orders" and within the WordPress panel I have created several "categories" within orders (terms).
I have a term called "Madrid", and I want to show the post of that term on a page-template. How can I do it? It is killing me literally.
I appreciate your help.
-- This is the loop and the code I used in a normal "taxonomy-template.php" and its work fine, but now I need to show the same information but only showing the post associated with the term "Madrid" in a page template.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php endwhile; endif; ?>
Share
Improve this question
edited Dec 3, 2018 at 11:15
Krzysiek Dróżdż
25.6k9 gold badges53 silver badges74 bronze badges
asked Dec 2, 2018 at 20:49
ctrljctrlj
112 bronze badges
2
-
If I understood correctly, you need to do a custom query that returns the grouped
post_typeand the orderstaxonomywith value Madrid. – Alvaro Commented Dec 2, 2018 at 22:46 - I need a query just like the wp_query for, example, 'cat=5' but for custom post type taxonomy. – ctrlj Commented Dec 3, 2018 at 8:14
2 Answers
Reset to default 0I found the solution by myself, I leave it here in case someone is interested:
<?php $args = array(
'post_type' => 'agrupados',
'tax_query' => array(
array(
'taxonomy' => 'pedidos',
'field' => 'slug',
'terms' => 'ferrol',
),
),); $the_query_slide = new WP_Query( $args ); if ( $the_query_slide->have_posts() ) {while ( $the_query_slide->have_posts() ) {$the_query_slide->the_post();?>
<?php
/* variables para cada imagen */
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php }} wp_reset_postdata(); ?>
In your code you print posts based on global $wp_query object. If you want to print some posts on another template, not using global query, then you'll have to create your custom query object:
<?php
$groupped = new WP_Query( array(
'post_type' => 'grouped',
'tax_query' => array(
array(
'taxonomy' => 'orders',
'field' => 'slug',
'terms' => 'madrid',
),
),
) );
while ( $groupped->have_posts() ) :
$groupped->the_post();
$full = get_the_post_thumbnail_url(get_the_ID(),'full');
$large = get_the_post_thumbnail_url(get_the_ID(),'large');
$medium = get_the_post_thumbnail_url(get_the_ID(),'medium');
$thumbnail = get_the_post_thumbnail_url(get_the_ID(),'thumbnail');
?>
<div class="col col-md-flex-6 col-lg-flex-3 ">
<picture class="cat-agrupados-img">
<source media="(min-width: 768px)" srcset="<?php echo esc_url($thumbail); ?>">
<img src="<?php echo esc_url($medium);?>" alt="<?php the_title(); ?>">
</picture>
<h2 class="cat-agrupados-titulo-pedido">Pedido agrupado en <?php the_title(); ?></h2>
<p class="cat-fecha-publicacion">Fecha de publicación: <strong><?php the_date(); ?></strong></p>
<p class="cat-agrupados-zona">Zonas: <strong><?php echo get_post_meta( get_the_ID(), 'yourprefix_agrupados_poblaciones', true ); ?></strong></p>
<a href="<?php the_permalink(); ?>" class="cat-agrupados-link">Ver pedido agrupado</a>
</div> <!--cierre columna-->
<?php endwhile; wp_reset_postdata(); ?>
本文标签: wp queryWordpress loop Show only a Custom Post Type Taxononmy TERM
版权声明:本文标题:wp query - Wordpress loop: Show only a Custom Post Type Taxononmy TERM 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749132622a2320846.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


post_typeand the orderstaxonomywith value Madrid. – Alvaro Commented Dec 2, 2018 at 22:46