Skip Navigation

[Resolved] Some shortcodes are not being executed in a view

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 9 months ago.

Assisted by: Minesh.

Author
Posts
#2685335
screenshot 2024-02-26 at 12.35.30.png

Hi there,

Some background:

+ My website is using the legacy Types + Views + Layouts plugins.

+ I've created a custom post type named Case Study.

+ The Case Study custom post type has several custom fields, including a repeatable field group named "Case Study Media." The group contains two custom fields:
__"Media Embed Code" (WYSIWYG)
__"Media Caption" (multiple lines)

+ The fields are output via a view named "View of Case Study Media" (ID: 3817, slug: view-of-case-study-media). This view is inserted into a layout named "Template for Case Studies" (ID: 3734, slug: template-for-case-studies).

Here's the problem. I have two pages with different shortcodes in the "Media Embed Code" field:

Page 1: hidden link
"Media Embed Code" field content: [video width="1920" height="1080" mp4="hidden link"][/video]

Page 2: hidden link
"Media Embed Code" field content: [embed]hidden link;

Page 1 correctly renders the video on the webpage in the right-hand column (see attached). Page 2 renders nothing at all in the right-hand column. We're expecting to see the Vimeo video in the right-hand column.

Please let me know if you require any further details.

Thank you!

Saul

#2685449

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can not run the Embed shortcode by just adding it as a custom field value. Embed shortcode does have some dependencies and you can check more details about that with the following official Doc:
- https://codex.wordpress.org/Embed_Shortcode

To display the embed shortcode added as value - you will have to render the shortcode first and then you will be able to display it.

To do that, I've added the following shortcode by adding "Code Snippet" plugin:
- hidden link

add_shortcode("show_rfg_field_value",'func_show_rfg_field_value');
function func_show_rfg_field_value($atts,$content){
	global $post;
	global $wp_embed;

    $pattern = get_shortcode_regex();
	
	$value=get_post_meta($post->ID,'wpcf-case-study-media-embed-code',true);
	
    if (   preg_match_all( '/'. $pattern .'/s', $value, $matches )
        && array_key_exists( 2, $matches )
        && in_array( 'embed', $matches[2] ) ) {
		  return $wp_embed->run_shortcode($value);
		
	} else {
		return $content;
	}
}

Then I've added the above shortcode to your view's loop template as given under:
=> hidden link

<div class="case_study_resource_media_group">
  <div class="case_study_resource_media_item">[show_rfg_field_value]</div>
  <div class="case_study_resource_media_caption">[types field="case-study-media-caption"][/types]</div>
</div>

Can you please check it works as expected:
- hidden link