Skip Navigation

[Resolved] Inconsistent behaviour when using wpv-post-body without view_template argument.

This support ticket is created 8 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 10:00 - - - - -
- - - - - - -

Supporter timezone: Africa/Cairo (GMT+02:00)

This topic contains 13 replies, has 3 voices.

Last updated by Mohammed 8 years, 1 month ago.

Assisted by: Mohammed.

Author
Posts
#367867

Hi,

One of the core workflows I use with Views is to use [wpv-post-body] without a view_template argument so that the output is displayed using whatever content template has been set on the given post. This allows me to display different custom post types in one view, or even use different layouts for different posts of a single CPT.

This to me is one of View's most powerful and useful features.

Generally, this works really well, however in a recent upgrade I came across an issue where this has stopped loading the content template when the View is placed on an archive page.

Note, that the problem is not within the archive loop, but with a view placed into a widget on the page. The same widget works fine on other pages of the site (i.e. loads the correct content template), but it does not work on any of the archive pages.

Looking through the forum I found the following thread from 2014: https://toolset.com/forums/topic/wpv-post-body-does-not-render-post-content-using-template-on-wpviews-1-5-1/

In the last response posted by Juan, he says: "1. The wpv-post-body shortcode without attributes behaves differently depending whether it is used on a normal View (it renders the Template assigned to the current post, if any, or the actual post content) or a WordPress Archve (it renders the Templateassigned to that archive loop but in the first post, if any, or the actual post content). This should be normalized."

This refers to a slightly different scenario as I gather that's within the archive loop, while my view is just a normal view placed outside the main loop, however I suspect the problem might be related.

Can you please advise on how I should use the [wpv-post-body] shortcode in a View placed on an archive page (but outside the archive loop) in a way that will load the content template based on the post currently being displayed in the View?

It might be useful if Juan could have a look at this since he's already dealt with this issue before.

Regards,
Andy

#368113

Hello,

Thanks for contacting Toolset Support. I think the best and fastest procedure would be that I create the duplicate of your website and test it on my server.

For this I will need to request temporary access (WP-Admin and FTP) to your site.

You will find the needed fields for this below the comment area when you log in to leave your next reply. 
The information you will enter is private which means only you and I can see and have access to it.

// NOTE : Make sure that you have performed the backup before you let me access the site.

Thanks.

#370533

Hello,

Thanks for all the informations. However, I tried accessing the site, but the password is not correct.

Can you please make sure that the user has the same password as you stated above?

Thanks.

#370536

Try again now.

#370629

Hello,

It works now, I logged in.

So just to confirm my understanding of the issue before I forward it to our 2nd tier support.

When wpv-post-body is used without the template tag on Archive Pages it won't load any content, right?

Thanks.

#371304

That's correct.

#371410

Hello,

I forwarded this to our 2nd tier support team. They will take a look and contact you with further details.

Thanks.

#372763

Hello Andrzej,

I’m Mohammed Toolset support second tier and I have been escalated to this thread. I’ll give my best to help you to achieve your needs through Toolset components.

Thank you very much for the detailed information.

According to our documentation that describes "wpv-post-body" usage here: https://toolset.com/documentation/views-shortcodes/ , In the description section of the shortcode, you will find that it outputs the content of the current post or renders a content template.

I tried to replicate the issue on a local installation but I couldn't then checked your website which is "Fantastic" and found the following:
-You are using the view "List: Page Section by ID" which filters the "Page Sections" by the "Page Section" ID.
-There is something interesting here, you configured the "Page Sections" not to have a body field in Types > Post Types.
-So, when the "wpv-post-body" tries to load the post content, it doesn't find any content, So, it returns an empty result.
-You passed the ID 8 to the shortcode in the configured widget

-I went to Types > Post Types and edited the "Page Sections" custom post types to have "body" field in the post edit screen and filled it with a test data, and finally, it appeared.

Please go to the page you mentioned before that was containing the issue before and see if it works now.

Please let me know your feedback about that.

Thanks.

#372807

Thanks for the compliment. 🙂

In terms of your solution that's not quite what I'm looking for. The intended result is for the [wpv-post-body] (without a view template parameter) to use the view template specified in the "section" post.

On the home page (hidden link), this works, and you can see two copies of the footer content being output (from the two test shortcodes in hidden link).

On the archive page (hidden link) the exact same view, loaded in the same manner, doesn't work and you only see one set of content for the shortcode that specifies a view template parameter. The shortcode without one, now shows the content you put in but it should show the view template.

Basically, the objective is to make sure that the behaviour of that View is the same on both those pages.

Regards,
Andy

#374425

Hello Andrzej,

Thank you for your reply.

I got the point now. I checked some pages, views and the staff related to the issue in your website to replicate the issue in a fresh installation on my local machine and I was able to do that.

The issue is not present in all archives, you can see it in some of the custom posts archives, some of the taxonomies archives but not with the standard archives.

Anyway, this shouldn't happen.

Since I'm able to replicate the issue locally, there is no need for more information from your side, I will check the issue on my local machine to figure it out and get back again to you.

Thanks.

#374473

Hi Andrzej,

I've debugged the issue and I found that this may be an issue in the Views plugin.

I shared my findings with the development team and waiting for their response.

Please wait until I get any news from the development team.I will notify you with the updates once they respond to me.

Thanks.

#374731

Hello Andrzej,

Here is the development team response:

There is no way to insert this wpv-post-body shortcode without a view_template attribute unless you do it writing manually - all our GUIs include it by design.

Why did this work in some cases?
This shouldn't. But In fact, some users are relying on this behavior, and any attempt to change this has triggered some reactions from our clients. So, we have not to modify this behavior.

Thanks.

#375297

Hi Mohammed,

I understand this is undocumented functionality, but nonetheless it's something that exists in Views and, as you said, a number of users have found this behaviour useful.

In my personal opinion, the "polymorphic" behaviour of templates to Views I can achieve with this functionality is one of the most powerful aspects of the Views plugin and I use it extensively.

Saying that, in other use-cases I achieve similar functionality by explicitly specifying the template using a shortcode. Maybe this can be applied here to explicitly set the template argument, which is still dynamically generated during run-time.

I will look into this from my end, but I'd be happy if you guys could let me know if you already have a solution for this.

In any case, I don't think this is an issue that the dev team can just ignore. Seeing as you didn't explicitly block this functionality from working in the first place, I think one way or the other, you guys need to find a way to normalise the behaviour and officially support it.

I'll leave this issue open for now.

Regards,
Andy

#375465

Hello Andrzej,

Thank you for your understanding.

After discussing the issue again with the development team, they decided not to apply this functionality because it may cause inconsistency in the Views plugin.

I may provide this workaround which I tried locally and worked perfectly because we may make selecting the template very strict in some future release.

The following code will enable you to control the content template that is being displayed depending on some conditions.

You can control it depending on any information in the post or even a post meta.
You can add this code in your theme's functions.php file and adjust it to match your requirements.

add_filter( 'wpv_filter_force_template','force_post_template',3,10 );
function force_post_template($template_selected, $id, $kind ){
	global $post;
	if($post->post_type=='course') {
		$template_selected= 56;
	}
	return $template_selected;
}

Notes:
** The $kind parameter: the kind of place where this template is being used like the following:
***[ single-{post-type}, singular, archive-{post-type}, archive-{taxonomy}, archive, listing-{post-type} ]
***Example: "archive-category" (for standard wordpress category archives)
** 56 is the ID of the preferred template
** course: is the currently displayed poost type, you can change it to fit your needs

I think that this code will enable you to have a good control over the different post types and different views.

Please let me get your feedback about this.

Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.