Passer la navigation

[Résolu] List all the existing Views using php

This support ticket is created Il y a 3 années et 6 mois. 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
- 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 -

Fuseau horaire du supporter : Asia/Kolkata (GMT+05:30)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par Paul Marconi Il y a 3 années et 6 mois.

Assisté par: Minesh.

Auteur
Publications
#2249985
views.PNG

Hi there,

Is there a way to list all the toolset Views (just the name and slug) using php?
I have created 2 Views under Toolset > Views, but would like to display all the names/ slugs of the Views to a php template.
Is there a way to do that using PHP?

Thank you!

#2250815

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There is no way to get view's list you created using Toolset but you should have to run a custom WordPress query where you should query the post type "view" and it will return you all posts with post type view.

As you are using the PHP template, you can query using the WP_Query to find posts belongs to post type "view".

For example:

// WP_Query arguments
$args = array(
	'post_type'              =>  'view',
	'post_status'            =>  'publish' ,
);

// The Query
$query->posts  = new WP_Query( $args );

You will find all the posts belongs to post type view with $query->posts variable. Can you please check if that helps.

#2250903

Thank you Minesh! Using the default WP_Query works to display all created toolset Views.

My issue is resolved now. Thank you!