Display custom metadata field in a CPT
-
I have added a event date metadata field to my CPT called events.
I am now trying to display the event date with the display posts shortcode but can’t get it to work. Any help?I found this https://gist.github.com/billerickson/1209601 and when I tried using it, the span appears, but there is no content inside the span.
This was my code.
add_filter( 'display_posts_shortcode_output', 'be_display_posts_custom_fields', 10, 6 ); function be_display_posts_custom_fields( $output, $atts, $image, $title, $date, $excerpt ) { // Get our custom fields global $post; $event_date = esc_attr( get_post_meta( $post->ID, 'event_date', true ) ); // If there's a value for the custom field, let's wrap them with <span>'s so you can control them with CSS if( isset( $event_date ) ) $event_date = '<span class="event_date">' . $event_date . '</span> '; // Now let's rebuild the output. $output = '<li>' . $image . $title . $event_date . $type . $price . $date . $excerpt . '</li>'; // Finally we'll return the modified output return $output; }
I added this in the display-posts-shortcode.php
Any help in whats going wrong would be greatly appreciated!
Thanks!
- The topic ‘Display custom metadata field in a CPT’ is closed to new replies.