Support

Account

Home Forums General Issues Post object as ACF – shortcode problem

Solved

Post object as ACF – shortcode problem

  • Hello,

    I use two custom post types: eventtype and event. The eventtype has a wysiwyg field that may contain any kind of shortcodes. I added the eventtype to the event as a custom field (post object). If I check only the eventtype content, it’s all good, but when I processing events, and I print eventtype content, the shortcodes inside the eventtype content doesn’t show.

    $fields = get_fields(get_the_ID()); // get event custom fields
    if ($fields):
      $event_type = get_field('eventtype'); // get event type custom field 
      if ($event_type): 
        echo ($event_type->post_content);
      endif;
    endif;

    Can you help me with this?

  • when you access the post content this way

    
    $post->post_content
    

    shortcodes are not run. You either need to use a loop as described in the post object field documentation with functions like the_content() or you must call

    
    echo do_shortcode($post->post_content)
    
  • Solved, thank you very much!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.