Skip to main content
deleted 4 characters in body
Source Link
Howdy_McGee
  • 20.8k
  • 24
  • 91
  • 175

I have a custom post type called 'portfolio'portfolio and a taxonomy called "locations'locations. In the taxonomy I have various terms, like 'paris', 'berlin', 'london'paris, berlin, london etc.

How can I get only the posts which are related to one term, e.g. paris?

I am trying the following code, yet it gives me the ALL the posts of the taxonomy portfolio and not just of one term:

$args = array(
    'post_type' => 'portfolio',
    'locations' => 'paris'
);
$my_query = new WP_Query( $args );

if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
    endwhile;
}
wp_reset_query();

I have a custom post type called 'portfolio' and a taxonomy called "locations'. In the taxonomy I have various terms, like 'paris', 'berlin', 'london' etc.

How can I get only the posts which are related to one term, e.g. paris?

I am trying the following code, yet it gives me the ALL the posts of the taxonomy portfolio and not just of one term:

$args = array(
    'post_type' => 'portfolio',
    'locations' => 'paris'
);
$my_query = new WP_Query( $args );

if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
    endwhile;
}
wp_reset_query();

I have a custom post type called portfolio and a taxonomy called locations. In the taxonomy I have various terms, like paris, berlin, london etc.

How can I get only the posts which are related to one term, e.g. paris?

I am trying the following code, yet it gives me the ALL the posts of the taxonomy portfolio and not just of one term:

$args = array(
    'post_type' => 'portfolio',
    'locations' => 'paris'
);
$my_query = new WP_Query( $args );

if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
    endwhile;
}
wp_reset_query();
formatted code, removed fluff
Source Link
Howdy_McGee
  • 20.8k
  • 24
  • 91
  • 175

I am going crazy here as I assume it is quite simple, but I just cannot get it to work.

I have a custom post type called 'portfolio' and a taxonomy called "locations'. In the taxonomy I have various terms, like 'paris', 'berlin', 'london' etc.

How can I get only the posts which are related to one term, e.g. 'paris'paris?

I am trying the following code, yet it gives me the ALL the posts of the taxonomy 'portfolio'portfolio and not just of one term:

<?php
$args=array$args = array(
    'post_type' => 'portfolio',
    'locations' => 'paris'
);
$my_query = null;
$my_query = new WP_Query( $args ); 

if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
    endwhile;
}
wp_reset_query();  
?>

Hope someone can help!

Thank you!

I am going crazy here as I assume it is quite simple, but I just cannot get it to work.

I have a custom post type called 'portfolio' and a taxonomy called "locations'. In the taxonomy I have various terms, like 'paris', 'berlin', 'london' etc.

How can I get only the posts which are related to one term, e.g. 'paris'?

I am trying the following code, yet it gives me the ALL the posts of the taxonomy 'portfolio' and not just of one term:

<?php
$args=array(
'post_type' => 'portfolio',
'locations' => 'paris'
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query();  
?>

Hope someone can help!

Thank you!

I have a custom post type called 'portfolio' and a taxonomy called "locations'. In the taxonomy I have various terms, like 'paris', 'berlin', 'london' etc.

How can I get only the posts which are related to one term, e.g. paris?

I am trying the following code, yet it gives me the ALL the posts of the taxonomy portfolio and not just of one term:

$args = array(
    'post_type' => 'portfolio',
    'locations' => 'paris'
);
$my_query = new WP_Query( $args ); 

if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
    endwhile;
}
wp_reset_query();
Source Link
anna
  • 23
  • 1
  • 1
  • 6

Get posts of ONE taxonomy term of custom post type

I am going crazy here as I assume it is quite simple, but I just cannot get it to work.

I have a custom post type called 'portfolio' and a taxonomy called "locations'. In the taxonomy I have various terms, like 'paris', 'berlin', 'london' etc.

How can I get only the posts which are related to one term, e.g. 'paris'?

I am trying the following code, yet it gives me the ALL the posts of the taxonomy 'portfolio' and not just of one term:

<?php
$args=array(
'post_type' => 'portfolio',
'locations' => 'paris'
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query();  
?>

Hope someone can help!

Thank you!