MB Relationship WP_Query no longer works in Meta Box AIO 1.14.1 and 1.14.2
Support › MB Relationships › MB Relationship WP_Query no longer works in Meta Box AIO 1.14.1 and 1.14.2Resolved
- This topic has 4 replies, 2 voices, and was last updated 3 years, 9 months ago by
Paul Wenzel.
-
AuthorPosts
-
July 30, 2021 at 2:36 AM #29767
Paul Wenzel
ParticipantThis worked prior to Meta Box AIO 1.14.1 and 1.14.2:
$connected = new WP_Query( [ 'relationship' => [ 'id' => 'podcasts_to_episodes', 'from' => get_the_ID(), // the ID of the podcast (a custom post type) ], 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, 'post_status' => 'publish' ] );
Now
$connected->post_count
results in0
.I also tried
MB_Relationships_API::get_connected
but it also yielded zero results.Do I need to change anything about my code to support the latest version of MB Relationships?
Thanks!
July 30, 2021 at 11:34 AM #29775Long Nguyen
ModeratorHi Paul,
I've tested the query by relationship again but not see any issue. Can you please share the code that creates the relationship? And re-check the episode posts are published.
July 31, 2021 at 3:35 AM #29809Paul Wenzel
ParticipantHere's some snippets from my Podcast to Episodes relationship. As far as I can tell, this part continues to work fine in the last few updates of Meta Box AIO. Something is different about the way related posts are queried, however.
// register relationship add_action('mb_relationships_init', array($this,'podcasts_to_episodes_relationship')); function podcasts_to_episodes_relationship () { MB_Relationships_API::register( array( 'id' => 'podcasts_to_episodes', 'reciprocal' => true, 'from' => array( 'object_type' => 'post', 'post_type' => 'episode', 'admin_column' => true, 'meta_box' => [ 'title' => 'Podcast', ], ), 'to' => array( 'object_type' => 'post', 'post_type' => 'podcast', 'admin_column' => false, ), )); } ... // link episode id to podcast id MB_Relationships_API::add( $episode_id, $podcast_id, 'podcasts_to_episodes');
July 31, 2021 at 10:53 PM #29818Long Nguyen
ModeratorHi Paul,
Can you please check a post Episode if that is connected to a post Podcast when editing the post? It is possible that the connection is not set then the query does not find the post connected.
If you call the method
add
in your class, it should be hooked to the actionmb_relationships_init
add_action( 'mb_relationships_init', function () { MB_Relationships_API::add( 123, 456, 'podcasts_to_episodes'); } );
August 3, 2021 at 2:57 AM #29855Paul Wenzel
ParticipantI was able to solve the issue by passing
'post_type' => 'episode'
with myWP_Query
call noted above.It now looks like this:
$connected = new WP_Query( [ 'relationship' => [ 'id' => 'podcasts_to_episodes', 'from' => get_the_ID(), // You can pass object ID or full object ], 'orderby' => 'date', 'order' => 'DESC', 'paged' => $paged, 'post_status' => 'publish', 'post_type' => 'episode' ] );
I wasn't using this before, but it looks like that resolves my issue. The
post_type
parameter appears to be required after this change ininc/query/post.php
, introduced in MB Relationships 1.10.6:https://github.com/wpmetabox/mb-relationships/commit/e48e19322b4d9e13e3942c78fd27278a311e8080
-
AuthorPosts
- You must be logged in to reply to this topic.