Navigation überspringen

[Gelöst] Display Views Output In Dashboard Widget?

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

The issue here is that the user wanted to render their view on a custom dashboard widget.

Solution:

This can be done by using the following API function to render you view inside the custom widget on the backend.
https://toolset.com/documentation/programmer-reference/views-api/#render_view

This support ticket is created vor 6 Jahren. 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Dieses Thema enthält 4 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von julieP vor 6 Jahren.

Assistiert von: Shane.

Author
Artikel
#1177665

I have a custom widget that contains a simple SQL query and displays the results in a widget in the wp-admin dashboard. I'd like it to give me more information so I'd like it to also show the value of a custom field with the results conditional on the value of a different custom field. This seems complicated to achieve via an SQL query so I'm wondering is it possible use Views to achieve this and how would I integrate the View into my widget please?

#1177718

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Juilie,

Thank you for getting in touch.

You could add this function below to your custom widget
https://toolset.com/documentation/programmer-reference/views-api/#render_view

Please let me know if this helps.
Thanks,
Shane

#1177725

Hi Shane

Thanks for a quick response.

That looks like it might be what I need. Will investigate further tomorrow.

Quick question: in the example given in the documentation you linked to, what might myattribute and myvalue be? The documentation states only name, title or ID can be passed so a little puzzled. Thanks

$args = array(
    'title' => 'My View name',
    'myattribute' => 'myvalue'
);
echo render_view( $args );
#1177733

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Juilie,

This can be anything really.

Especially if you add a filter to your view and set the filter to get the value from a shortcode attribute.

So for example you have your normal view shortcode.
[wpv-view name='my-view' vehicle_id='12345']

Then the function equivalent would be.

$args = array(
    'title' => 'My View',
    'vehicle_id' => '12345'
);
echo render_view( $args );

Please let me know if this is clear.
Thanks,
Shane

#1178965

OK that makes sense, thanks (have tested and it does what I was hoping for)