Open vguenichon opened 7 years ago
You should not include the class file inside a shortcode function, instead include it in the root of your functions.php
file. The class implements several hooks that are not available if executd inside add_shortcode
.
include_once(TEMPLATEPATH . 'inc/multisite-query.php');
function events_vc($atts, $contents = null) {
// code here...
}
add_shortcode('events_vc_output', 'events_vc');
OK Done but not working too.
Is it working if you perform this query outside of the shortcode?
Good question. I didn't think about doing that because I need it inside obviously. And your guess is right : it works outside (some problems with the orderby but it works).
No no... I made the same mistake than another time. As I imported the posts from a site to the main, I thought it was working. But it returns only posts from the main website.
I must admit that I'm not completely sure that the class is working properly with the latest WP version, since it's been 2 years since my last commit. I'll have time to test it tomorrow and let you know. I can't tell by your code if there's something wrong on your end.
Thanks a lot Miguel for taking care of this issue.
Miguel, I'm using another way to achieve what I want. But still interested in this network query. Should be native within Wordpress ! For instance, I'm using switch_to_blog in a foreach loop. Then after that, I order the posts by date from the client side. And it does the trick.
Hi, I encounter a similar problem with other way like yours to query the network. Maybe you'll have an idea. I use your class in a shortcode built for Visual Composer. And it returns only posts from the main site. Here's the code: