Skip Navigation

[Resolved] duplicate view is giving an content template I can not delete

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 7 replies, has 3 voices.

Last updated by corineV 1 year, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2500885
Schermafbeelding 2022-11-21 om 16.22.17.png
Schermafbeelding 2022-11-21 om 16.24.08.png

I use legacy views to manage a page overview with different categories of my cpt. Each categorie is displayed with an legacy view with a querry filter.
Because the views are almost the same (onlye the querry filter is different) I use the legacy version (duplicate a block view is not possible I suppose).
Every time I duplicate the legacy view, it duplicates the content template as well. But I want to use the same content template each time. No problem, I edit the code a bit.

But the (only backend) problem is: I can not delete the unused content templates.
In the view I cannot choose an other content template.

What is the link to your site? hidden link
But the site is still under construction. I am happy to give the credentials.

#2501203

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Corine

I guess it is not anticipated that you would swap around which template the View refers to, hence there are no controls for managing that.

The solution is fairly simple, but it involves updating the database either directly (e.g. using phpMyAdmin) or writing a query to make changes.

Specifically, the details of the View are stored in wp_posts, and so the View also has certain entries in wp_postmeta for settings etc.

One such entry has the meta key "_view_loop_template", whose value is the ID of the linked content template.

You can either delete those entries to un-link the templates from the Views (free-ing them up to be deleted), or you could even change the ID to the ID of the single template that the Views all refer to (in which case it could be edited in any of the Views).

Is that something you can do yourself, or do you need some help?

#2501249

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

{ticket status updated}

#2503921

Hi Nigel,
That was not my intention either. I wanted to create multiple views with 1 content template. I remember that in the past (for gutenberg) this was very easy or happened automatically. I was also amazed at the amount of content templates and that I couldn't delete/unassign them.
I would be very happy if you would help me with that. The website is now online. I can send you login details.
The only content template I want to keep is "loop-item-sortiment".
Kind regards,
Corine

#2505545

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Corine,

Thank you for sharing these details and your observation is correct.

Whenever a view is created with a content template, an association is created between that view and the content template, in the database.

And when a duplicate of that view is created, another content template with that duplicated view is created with a similar association.

And as long as a content template is part of an association with a view, the option to delete it is not available in the list of content templates.

Since you don't need to maintain these associations between the views and the content templates, you can follow these steps:

1. Make a complete backup copy of the website.

2. Add the following code to the active theme's 'functions.php' file:


add_shortcode( 'custom_shortcode_SQL', 'custom_shortcode_SQL_func');
function custom_shortcode_SQL_func()
{
	global $wpdb;
	$sql = "DELETE FROM `wp_postmeta` WHERE meta_key='_view_loop_id'";
	$results = $wpdb->get_results($sql);
	$sql = "DELETE FROM `wp_postmeta` WHERE meta_key='_view_loop_template'";
	$results = $wpdb->get_results($sql);
}

3. Create a temporary page and include this new shortcode in the page's content:


[custom_shortcode_SQL]

Visit the page's front end, so that the code can be executed in the back end.

4. Check the content templates list and they'll be deletable, as the associations should have been deleted.

5. Once confirmed, you can delete the temporary page as well as remove the code from the "functions.php" file.

I hope this helps and please let me know if you need any further assistance with this.

regards,
Waqar

#2507537
Schermafbeelding 2022-12-01 om 17.05.30.png
Schermafbeelding 2022-12-01 om 17.05.41.png

Hi Waqar,
thank you very much for your answer. I've done the steps you mentioned, but to no avail.

I'm aware that the content template shouldn't be used by a view, because then I can't throw it away. But when I open the view, there is no option to choose another content template. (see screenshots).

Cleared all cache in between, of course, just to be sure.
Hope you have another solution.
Kind regards,
Corine

#2508115

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

The most probable cause that the code didn't work could be that your website's database is using a different prefix, than the default 'wp_' one.

Please go to WP Admin -> Tools -> Site Health -> Info -> Database and see what "Table prefix" is being used by the database.
( example screenshot: hidden link )

You can then update the two instances of the "wp_" prefix with that actual prefix in the code that I sent and followed the same steps again.

Once, the associations between the content templates and views have been deleted, you'll be able to delete the unwanted content templates.

To connect an existing content template to a view and insert its shortcode in the loop editor, you'll see a "Content Template" button in the "Loop Editor" section of the view.
( screenshot: hidden link )

#2508163

Great, it works! Thank you Nigel and Waqar.

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