Skip Navigation

[Resolved] Vertical youtube video slider view for testimonials

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 5 replies, has 1 voice.

Last updated by Minesh 3 weeks, 4 days ago.

Assisted by: Minesh.

Author
Posts
#2841704

Tell us what you are trying to do?
I am building a 3-column slider to display YouTube Shorts (vertical format). I have created a CPT called 'Testimonials' with two custom fields: 'YouTube URL' and 'Quote'. The CPT title is the name of the person giving the testimonial.

I am facing two issues:

The Toolset YouTube block does not offer a 9:16 aspect ratio option.

I do not know how to create a slider based on a View."

#2841780

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

There is no such native feature. Maybe you want to use the module manager plugin that works with the legacy views.
=> https://toolset.com/home/module-manager/

To switch to legacy views and still using blocks, you should try to follow the following Doc:
- https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/

You can add custom css or JS to display the result as per your requirement.

Using blocks, for example, you may need to add custom CSS something like the following CSS can possibally do the job, adhust the code as required.

/* Toolset YouTube 9:16 aspect ratio */
.toolset-youtube-9x16 .wp-block-embed__wrapper {
    position: relative;
    width: 100%;
    padding-top: 177.78%; /* 9:16 ratio (16 / 9 * 100) */
    height: 0;
    overflow: hidden;
}

.toolset-youtube-9x16 iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#2841859

I don't know if I'm stupid or what, but I can't find the Toolset Module Manager plugin either by searching here on your website or in the OTGS Installer...

#2841862

Minesh
Supporter

Languages: English (English )

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

You can download the Module manager plugin from your account's download page:
- https://toolset.com/account/downloads/

Click on "Download Toolset Manually" and under section "Utility plugins".

#2841956

I've been "talking" with Phi Phan, the developer of the "https://wordpress.org/plugins/better-youtube-embed-block/" plugin which allows you to display vertical YouTube videos.

Since there was no support for the URL to be the value of a CPT, he suggested the following, I transcribe what we were talking about.

Me:
I’m using Toolset Types to create CPTs, and I want to display vertical YouTube videos with testimonials.

The CPT has a field called “Testimonial URL”, where the user pastes the YouTube URL of the testimonial.

I created a query for this CPT and wanted to use this plugin (which, by the way, is excellent!) to display these testimonials, but the problem is that I can’t set the URL as a dynamic field.

I can’t figure out how to solve this.

What I noticed is that with a Paragraph block, it allows me to insert an inline field. It would be great to be able to do the same with the YouTube block, inserting it and having the video URL come from an inline field.

Phi
Thanks for your excellent suggestion. WordPress 6.9 now supports binding custom attributes for any block, so I’ll add this feature in the next version after the holidays.

In the meantime, you can use the code below to bind a custom field to the url attribute of this block:

add_filter(
'block_bindings_supported_attributes_boldblocks/youtube-block',
function ( $attributes ) {
$attributes = [ 'url', 'caption' ];
return $attributes;
}
);
Best, and happy holidays,
Phi.

Me
I saw it in Attributes! What I don’t see are the Custom fields I created with Toolset types

Phi

This feature only adds support for binding a custom field from a dynamic binding source to the url attribute. To bind a custom field to the url attribute, the field must be supported as a dynamic binding source.

I don’t have experience with Toolset, but if you don’t see your field listed as a binding source, it likely doesn’t support dynamic binding for its custom fields.

The simplest way to create a custom binding source is shown below.

add_action(
'init',
function () {
register_meta(
'post',
'youtube_video_url',
array(
'show_in_rest' => true,
'type' => 'string',
'default' => 'hidden link',
'single' => true,
)
);
}
);

add_filter(
'get_post_metadata',
function ( $value, $post_id, $meta_key ) {

if ( $meta_key === 'youtube_video_url' ) {
// Return the real value. Replace the field name with your real field name.
return get_post_meta( $post_id, 'wpcf_testimonial_url', true );
}

return $value;
},
10,
3
);
Contract
This approach registers a fake post meta field as a binding source, then hooks into the get_post_metadata filter to return the real value from your custom field.

Replace wpcf_testimonial_url with your own field slug. It looks like Toolset stores custom fields with the wpcf_ prefix, but I’m not completely sure. If your fields don’t use that prefix, just use the field slug as-is.

Once this code is in place, you can bind the youtube_video_url field to the url attribute of the YouTube block.

You can also ask Toolset for further support on this binding stuff.

_______

I still haven't managed to get it to display the value even though I changed the value in the filter:

wpcf_testimonial_url

to

wpcf-url-youtube

any ideas?

#2842386

Minesh
Supporter

Languages: English (English )

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

Honestly, I do not have any experince with the plugin "better-youtube-embed-block" and the code you shared is from Dev and they know the best and what could be the possible required fixes or code enhancements should be added in order to work Toolset custom field and "better-youtube-embed-block" with dynamic sources.

I can check and try once if you share problem URL and admin access details and see if I can able to offer you any sort of solution. However - It's better if you can check with them and if they have any hook/filters to attach Toolset custom field to the youtube block they offer. Because for instance even if I fix it for now and leter with the code changes the plugin author will make in order to make this work as require and our fix will be broken.

I would say its better choice if you could wait a little and check with plugin author and they should provice official way to use Toolset custom field(s) with their youtube block it will be safe solution to use.

I hope this makes sence.