Home › Toolset Professional Support › [Resolved] echo do shortcode with condition shortcode doesn't work
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 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Tagged: Views, Views API, Views plugin
Related documentation:
This topic contains 13 replies, has 2 voices.
Last updated by SarahN8863 4 years, 9 months ago.
Assisted by: Minesh.
I am trying to: insert this code in the php template but it doesn't work because of the quotes (or maybe another issue?)
<?php echo do_shortcode( '[wpv-conditional if="('[wpv-post-type]' eq 'organizations)"]
[wpv-view name="organisations-communities-partners" limit="-1" offset="0"]
[/wpv-conditional]
?>
Link to a page where the issue can be seen: hidden link
I expected to see: the cpt (organisations) posts of the view
Instead, I got: or fatal error, or just empty if i tried when i tried this.
<?php echo do_shortcode( '[wpv-conditional if="(\'[wpv-post-type]\' eq \'organizations\')"]
[wpv-view name="organisations-communities-partners" limit="-1" offset="0"]
[/wpv-conditional]
?>
Hello. Thank you for contacting the Toolset support.
I am not sure why you are using shortcodes as that is not the recommended way to display output with PHP template files.
For example - you can check the current post type using if condition as follows:
global $post; if($post->post_type=="organizations") { echo "whatever"; }
And Toolset also offers the PHP API to render the view using PHP function: render_view()
For example:
$args = array( 'id' => '9999', ); echo render_view( $args );
Where:
- You can replace 9999 with your original view ID.
More info:
=> https://toolset.com/documentation/programmer-reference/views-api/
Please let me know if you need further assistance or questions.
I tried to add the code with your solution proposal, but there is an issue.
Actually, i wanted to set up the taxonomy template. I have taxonomies, that are shared by different custom post types, everyone has a different loop/design.
I wanted that when you arrive on a taxonomy term page, you see posts from custom post type 1 first, then custom post type 2. etc.
But i don't why it doesn't show all the posts from the 3 custom post types.
Here is a page as an example where i wanted to set it up: hidden link or hidden link
And Here is the code i tried:
<h3>Affiliated Organizations</h3>
<?php global $post;
if($post->post_type=="organizations") {
echo do_shortcode( '[wpv-view name="organisations-loop" limit="-1" offset="0"]' );
}
else {echo 'No affiliated organizations were found in this section.';}
?>
<h3>Events</h3>
<?php global $post;
if($post->post_type=="events") {
echo do_shortcode( '[wpv-view name="events-loop" limit="-1" offset="0"]' );
} else {echo 'No events were found in this section.';}
?>
<h3>Hot Topics</h3>
<?php global $post;
if($post->post_type=="hot-topics") {
echo do_shortcode( '[wpv-view name="hot-topics-loop" limit="-1" offset="0"]' );
}
else {echo 'No hot topics were found in this section.';}
?>
As I understand, you want to group posts on the taxonomy term archive page by post type?
1. Yes, this is what i meant for the main taxonomy page.
2. Then, i will also need than when you click on one custom post type/taxonomy (don't know yet how), you have the loop only for this taxonomy and this unique post type.
I hope i am clear enough.
It looks like you when I say group by post type, it will display the post of specific post type first and then another post type.
I do not understand what you mean to say by with your 2nd point. Maybe you should share a test example or few screenshots what exactly output you are looking for and once I understand you requirements I will be able to guide you in the right direction.
I don't have yet screenshots to show, since it's not ready yet.
But i'll try to explain.
3 cpt: organizations, events and hot topics. i set up already 3 toolset views for each custom post type loop.
taxonomy: pillar. taxonomy terms: communities partners, jewish-life-growth-development, etc.
What i will need:
Request #1: in pillars page i will have a list of all taxonomy terms. when you click on a term (taxonomy.php), it has to display all organizations with that term, then all events with that term, and all hot topics with that term.
(To be more precise, i will need only 3 first posts for each + a button which leads to all posts of that term as request #2)
Request #2: in cpt pages, for example organisations, i will have a list of of all the taxonomy terms, and when i click on that term, i arrive to a page with only this cpt posts (our example: organisations) with that term i clicked on.
As I understand now based on the information you shared.
For instance, this is the taxonomy archive page: hidden link
- with an above taxonomy archive page, you want to display 3 posts of your each post type once after another - am I right?
If I am not right, for Request #1 what is the page where you want to implement such function.
Yes, you are right for request #1.
Great. Can you please send me access details so I can adjust the code.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Can you please check now: I've added the View all links to for all the post types.
<a href="?post_type=organizations"> View All </a> <a href="?post_type=events"> View All </a> <a href="?post_type=hot-topics"> View All </a>
I also would like to tell you that this is theme customizations and we do not offer support for such custom edits (theme customizations). If you need further help with your such custom edits you are welcome to hire a pro Toolset contractor using from our list of certified contractors:
=> https://toolset.com/contractors/
It doesn't work at all, the link hidden link you added does exactly the same as the cpt archive page hidden link, it doesn't filter the cpt posts of that term.
I need assistance to have an automatic view of current cpt with specific taxonomy term...
Can you please check now: hidden link
I've adjusted the code to your taxonomy archive as given under:
<?php if(!isset($_GET['post_types'])) { ?> <?php $queried_object = get_queried_object(); echo do_shortcode( '[wpv-view name="organisations-loop" limit="3" offset="0"]' ); ?> <a href="?post_types=organizations"> View All </a> <h3>Events</h3> <?php echo do_shortcode( '[wpv-view name="events-loop" limit="3" offset="0"]' ); ?> <a href="?post_types=events"> View All </a> <h3>Hot Topics</h3> <?php echo do_shortcode( '[wpv-view name="hot-topics-loop" limit="3" offset="0"]' ); ?> <a href="?post_types=hot-topics"> View All </a> </div> <?php } else { if($_GET['post_types']=="organizations"){ echo do_shortcode( '[wpv-view name="organisations-loop"]' ); } else if($_GET['post_types']=="events"){ echo do_shortcode( '[wpv-view name="events-loop"]' ); } else if($_GET['post_types']=="hot-topics"){ echo do_shortcode( '[wpv-view name="hot-topics-loop"]' ); } ?> <?php } ?>
It should work now as expected.
My issue is resolved now. Thank you!