I have got a shortcode that displays a custom post type, via a foreach
. The shortcode has been used in the standard post type. I have used the_title();
in the shortcode. the_title();
outputs the post_title of the standard post type (which the shortcode is in), rather than the_title();
of the custom post type. My code:
function faq_register_shortcode() {
add_shortcode( 'display_faqs', 'mp_faq_shortcode' );
}
function mp_faq_shortcode() {
$args = array( 'post_type' => 'faq_type_mp', 'numberposts' => 3, 'post_status' => 'any', 'post_parent' => null );
$attachments = get_posts( $args );
if ($attachments) {
foreach ( $attachments as $post ) {
the_title();
the_content();
}
}
}
So for example, if the standard post type (which the shortcode is in), had a post_title
of 'this is the standard post type', this is what is outputted in the shortcode. I want to display the post_title
which belongs to the custom post type, NOT the standard post (which the shortcode is in).
What have I done wrong please?