0
votes

I am trying to automatically display all the custom fields of a custom post type alongside it's title and content.(Not in admin but on my actual site)

I need to be able to do this with an action hook or filter, rather than creating a template.

After scouring the web I was able to find the 'publish_{custom_post_type_name}' hook:

function my_cool_hook() {
echo get_post_meta($post->ID, 'my-custom-field-name', true); 
}

add_action( 'publish_past_symposia', 'my_cool_hook' );

but it doesn't seem to do anything when I view my published custom post type on my site. Any ideas?

1

1 Answers

0
votes
add_action( 'publish_past_symposia', 'my_cool_hook' );

This hook triggered only if PUBLISH post type.
YOu need to trigger the hook on web part - so...

add_filter('the_content', 'my_cool_hook');
function my_cool_hook($content){
    return $content.get_post_meta(get_the_id(), 'my-custom-field-name', true);
}

now the content body filtred and your string from custom fields added.