Skip Navigation

[Résolu] php of a view with shortcode attribute

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

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 – 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)

Marqué : 

This topic contains 7 réponses, has 2 voix.

Last updated by Ido Angel Il y a 4 années et 5 mois.

Assisted by: Shane.

Auteur
Publications
#1379913

Hey,
I have 2 post types: posts and lawyers.
I have a taxonomy of "working areas" which I appended to both post types. I did that, because I want to take the single-post template for posts and in each post display a list of lawyers with the same work area.
I created a view for lawyers, then added a filter for the work area with a shortcode attribute 'areafrompost", something like this:

[wpv-view name="side-lawyers" areafrompost="[wpv-post-taxonomy type='work-area' format='slug']"]

and now i need to place this inside the posts single-post.php template (because the lame theme I'm using won't let me rebuild the content template with toolset - but that's another issue).
how would I do this?
i know how to render a simple view:

<?php echo render_view( array( 'name' => 'side-lawyers' ) );?>

but how to i add the shortcode attribute to be taken from the post current taxonomy?
thx!

#1380109

Shane
Supporter

Languages: Anglais (English )

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

Hi Ido,

Thank you for getting in touch.

You will need to do it like this.


<?php

 echo render_view( 
                         array( 'name' => 'side-lawyers',
                                     'areafrompost' => do_shortcode("[wpv-post-taxonomy type='work-area' format='slug']");
                                 ) 
                           );

?>

Please try this and let me know if it helps.
Thanks,
Shane

#1380143
Untitled-1.jpg

Thx dear Shane!

I'm getting an error in the do_shortcode line (see attached image)
what am i missing?

thx!

#1380155

Shane
Supporter

Languages: Anglais (English )

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

Hi Ido,

My apologies, it should be like this.

<?php
 
 echo render_view( 
                         array( 'name' => 'side-lawyers',
                                     'areafrompost' => do_shortcode("[wpv-post-taxonomy type='work-area' format='slug']")
                                 ) 
                           );
 
?>

Without the semicolon at the end of the do_shortcode.

This should work now.
Thanks,
Shane

#1380197

thx!
no errors - but i'm not getting the right result of the same taxonomy.
maybe i'm thinking wrong?

let's try to overview this again:

1. i have "posts" and "lawyers"
2. i have a taxonomy "work-areas" which is attached to both posts and lawyers
3. if a post has, for example, a "work area" of "environment" - I want it to display a list of lawyers under the same "work area" of "environment".

am i missing something?

thx again - as always.

#1380203

silly me.
i didn't need to use a shortcode attribute at all. instead, i had filtered the taxonomy according to "the same as the page where this View is shown" - and now it's working with the simple

<?php echo render_view( array( 'name' => 'side-lawyers' ) );?>

but i've learned something new 🙂
thx shane!

#1380205

Shane
Supporter

Languages: Anglais (English )

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

Hi Ido,

Right this should give you the desired results.

What you can do is to check your view to see if you are getting the right taxonomy terms being passed into the view.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute

Also you can try doing it like this.



<?php
  $terms = do_shortcode("[wpv-post-taxonomy type='work-area' format='slug']");
 echo render_view( 
                         array( 'name' => 'side-lawyers',
                                     'areafrompost' => $terms
                                 ) 
                           );
  
?>

Please let me know if this helps.
Thanks,
Shane

#1380229

silly me.
i didn't need to use a shortcode attribute at all. instead, i had filtered the taxonomy according to "the same as the page where this View is shown" - and now it's working with the simple

1
<?php echo render_view( array( 'name' => 'side-lawyers' ) );?>
but i've learned something new 🙂
thx shane!

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