Skip to content
Advertisement

How do I call post objects (products) custom fields using shortcodes on posts

I’m trying to show ‘featured products’ on blog posts. These featured products are to be selected with custom fields post objects on the back end for each post.

I have written up what I think the PHP should be – where am I going wrong? When I try to use the shortcode no code appears (but the shortcode text doesn’t show so it’s definitely added). Thanks 🙂

JavaScript

Advertisement

Answer

You have built your HTML in the $html variable but then you don’t do anything with it. The shortcode doesn’t automatically know that you want to display the $html variable so you need to return ( or echo) it at the end before the function finishes:

JavaScript

Reference: See the add_shortcode WP documentation

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement