Using Give_Payments_Query with switch_to_blog in multisite
-
Hi,
I’m setting up some custom shortcode functions in a multisite setup. I have 3 sites and want a shortcode to process and display massaged statistics of donations that were made across all the 3 sites.
I basically use something like this:
$blogs_ids=get_sites(); foreach( $blog_ids as $b ){ switch_to_blog( $b->blog_id ); ... $donations_obj = new Give_Payments_Query( array( 'give_forms' => $formIds, //all give-forms IDs 'number' => - 1, 'status' => array( 'publish' ), 'start_date' => date("Y-m-d H:i:s", $start_date), 'end_date' => date("Y-m-d H:i:s", $end_date) ) ); $donations = $donations_obj->get_payments(); ... restore_current_blog(); }
Unfortunately, complete payment info is only returned for the site you are currently on when calling the shortcode. Even though I see that the switch_to_blog does correctly change the db prefix, it seems that the Give_Payment Object for donations from the db table on other sites in multisite setup is missing almost all the info. Only id, post_date, post_status is there, all other details are missing, even form_id.
Anyone have any suggestion on what I’m missing? I could off course just do my own wp db queries, but I’d really prefer just to use the give functions. I already suspect that it some singleton problem with when the plugin is loaded vs the shortcode executed…
Any pointers would be appreciated.
- The topic ‘Using Give_Payments_Query with switch_to_blog in multisite’ is closed to new replies.