I’ve been beating on this one for a couple hours and haven’t figured out a solution yet. I searched these forums and Googled like mad.
I’m inserting a Posts module to display posts (actually products) from a specific category (not a custom post type). In the post content is a shortcode to display the product star rating (I’m using the YASR plugin - https://wordpress.org/plugins/yet-another-stars-rating/).
The problem - the shortcode doesn’t render in the Posts module.
Is there any way to get this to work?
The site is hidden and you need admin access to view it. Let me know if you’d like that…
Thanks for getting in touch! Yes, do you mind sending in the site URL as well as temp admin access so we can check? You can just use the private reply below.
I created a test page, ‘Test’, and place a Posts module there, set it to output only the Featured Images. I then edited Nuvoderm Nano Gold Facial Serum, placed the YASR shortcode on the Excerpt and it works just fine. You can enable the Excerpt meta box by hitting on the Screen Options on the top right and checking the Excerpt box.
I took a look and, unfortunately, the rating still isn’t displaying properly - it has the same issue as the ‘Recent Product Reviews’ section on the Home page in that the stars will show, but they won’t be filled yellow according to the actual rating.
If you look on the Home page in the Sidebar at the top, the Top Rated Products section also uses a YASR shortcode and it displays the way it should.
I’m starting to think this is an issue with YASR, as both BB and SRP (Special Recent Posts plugin) experience the same issue. However, if you think differently or have any insight as to why it may not be working, I’m ALL ears.
Ben has left for the day and I’m coming in a bit late on this one. If it would be ok with you, I am going to leave this for him when he gets in tomorrow. Let me know if otherwise and we’ll get in there to try to figure this out!
You’re off the hook - at least for this particular instance. I got a solution from the developer of YASR.
Apparently it needs to be within the loop to grab the post ID - neither SRP or BB apparently are within the loop when generating the post data.
Which brings me to another question - since this is probably the 4th or 5th time this year I’ve come across issues with plugins or themes and how they’re using the loop (or not), I’m curious if there’s some reason that these kinds of things (retrieving post data) aren’t run within it.
It’s late, so I may be not thinking this through properly, but I’d like to get some insight into the particular workings/non-workings of this problem.
Which brings me to another question – since this is probably the 4th or 5th time this year I’ve come across issues with plugins or themes and how they’re using the loop (or not), I’m curious if there’s some reason that these kinds of things (retrieving post data) aren’t run *within* it.
That’s a great question! There are a few things going on here so let me break it down a bit…
The main builder layout is being created within the main WordPress loop for the particular page you are on.
The Posts module is actually run in a loop as well, but it’s a secondary loop (if we override the main loop, the layout will break). I’m thinking this plugin isn’t working because it’s looking for posts in the main loop and can’t see posts in our secondary loop.
Let me play around with the YASR plugin and see if there is anything we can do to get it working.
I did some testing and I’m not sure why YASR isn’t working, it seems like it should. However, I did find out that you can explicitly set the post ID on the shortcode to get it working like so…
As always, I really appreciate your willingness to explain things and go the extra mile.
I’m the kind of person that would normally comb through the code to see if I can figure out what’s going wrong, but I’ve been so busy with client work lately that ‘play time’ has gone by the wayside. Feel free to get technical if you want with any explanation of the cause of the problem - but don’t feel you need to if time is of the essence.
Oh, sorry - didn’t see your other reply before I wrote my last one.
Explicitly setting the Post ID was the solution they provided me to get around the problem, but I’d still like to get it working without it, if possible, as my client…well, let’s just say that even using a plugin to show them the Post ID and asking them to put that information in the shortcode would be asking a bit much.
It looks like the issue is that shortcodes aren’t parsed in excerpts. Since they aren’t getting parsed in the secondary loop created by the post module, they are getting parsed in the main loop and picking up the post ID for the page.
To get them to be parsed in the secondary loop and pick up the correct post ID, you’ll need to add this filter in your theme…
Will this work for the content, rather than the excerpt? Another thing I’d like to avoid having the client do is filling out the excerpt. I’m hoping to have this work with the YASR shortcode above the post content.
I tested and the shortcode doesn’t appear to work in the content, even on a standard archive page when calling the_excerpt(). Calling the excerpt() should return a stripped down portion of the content, but it appears this shortcode doesn’t work in that scenario.
I dug through the plugin code and it looks like it’s coded to work this way, it doesn’t show the stars, it shows a message. You might try adding the filter I mentioned above and playing around with the plugin settings. There might be something I’m missing there.