Hello
I am trying to figure out how to create a query which will generate the link for the most recent newsletter posted to post type newsletter. I am working with the following code snippet, which is returning the correct number of results, but not displaying any of the values, and get\_permalink is showing the current page.
add_shortcode(‘youth_newsletter_shortcode’, ‘youth_newsletter’);
function youth_newsletter(){
$youth_newsletter = get_posts(array(
‘post_type’ => ‘newsletters’,
‘fields’ => ‘ids’,
‘orderby’ => ‘post_date’,
‘order’ => ‘DESC’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘newsletter’,
‘field’ => ‘slug’,
‘terms’ => ‘youth’
)
),
));
if (! empty ($youth_newsletter)){
$output = count($youth_newsletter) . ‘<br />’;
$output .= ‘<ul>’;
foreach ($youth_newsletter as $post){
$output .= ‘<li>post:’ . get_permalink( $post->ID) . ‘</li>’;
}
$output .= ‘</ul>’;
}
return $output;
}
I currently have 2 newsletters with the taxonomy ‘youth’. I am displaying this shortcode on a page called test-output, and this is the permalink it is displaying, but it is showing 2 lines of this permalink. If I try to do `$output .= ‘<li>post:’ . $post->post_title . ‘</li>’;`, I get two blank lines.
Any thoughts on what I’m doing wrong here?
[ad_2]