Site logo

Archived topic

Display post from custom post type

3 replies · Started by Rick on January 3, 2022

Viewing posts 1–4 of 4

I'm using this code in a Hook Element to display custom fields from the WordPress post type.

<?php
$website_custom_field = get_post_meta( get_the_ID(), 'website', true );
$email_custom_field = get_post_meta( get_the_ID(), 'email', true );

echo "<p style='padding-top:20px;'><strong>Website:</strong> " .$website_custom_field. "<br>";
echo "<strong>Email:</strong> " .$email_custom_field. "</p>";
?>

How would I do the same for the custom post type 'asd-providers'. I'm using Custom Post Type UI and Advanced Custom Fields in this scheme.

Thanks!
-Rick

Hi Rick,

If you want to use the same Hook element, you can edit its display rule location to add more custom post type.

Example: https://share.getcloudapp.com/kpu4ywDW

The code doesn't seem to need any change unless your CPT isn't set to have the specified custom fields. But if they are, then it should be fine as get_post_meta( get_the_ID() works in loops regardless of post type.

Yep, that did it... so easy. Thanks!
-Rick

No problem. Glad you got it sorted. :D

This archived topic is closed to new replies.