Forum Replies Created
-
AuthorPosts
-
Content Pilot
ParticipantI am still seeing this too on the latest version of MB. Only in visual mode.
November 18, 2018 at 8:33 AM in reply to: ✅Add meta data to field settings to identify as relationship field #12044Content Pilot
Participantbump
Content Pilot
ParticipantAnh, any update on either of these two issues?
- Add column in database table to store sort order on both sides of the relationship.
- Do not change sort order on save. I think Doug hit it on the head here. I have attorneys related to a practice area. Both sides of the relationship have a custom sort order that is thrown off by any of the posts being re-saved. If an attorney changes any content on his bio then saves the cpt entry, his name is pushed to the bottom of the list on the practice area page.
FYI, Clayton is my real name. Juanita is the office manager that bought/signed up this account when we purchased the bundle.
Also, if you give me a little hint about where to look for #2, I can trouble shoot on my end to speed it along.
October 26, 2018 at 9:33 PM in reply to: ✅pre_get_posts to get all posts connected to single object #11777Content Pilot
ParticipantAhhhh. Thank you for updating the plugin. I am off to the races now! Thanks for sticking with me on this one.
October 26, 2018 at 3:47 AM in reply to: ✅pre_get_posts to get all posts connected to single object #11767Content Pilot
ParticipantFor some reason my query is setting post type to
any. For some reason in parse_query it will change the post type any when using atax_query. I don't have atax_querynor do I have any taxonomies on these two post types.https://developer.wordpress.org/reference/classes/wp_query/parse_query/
Search for
post_typeadd_action( 'parse_query', 'rel_filter_query_by_relationship', 10, 1 ); /** * Filter the main query by using URL parameters * * @param object $query WP_Query. * @return object * * @since 3.6.8 */ function rel_filter_query_by_relationship( $query ) { $id = $query->get('relation_id'); $from = $query->get('relation_from'); $to = $query->get('relation_to'); if ( ! empty( $id ) && ! is_admin() && $query->is_main_query() ) { if ( ! empty( $from ) ) { $query->set( 'relationship', array( 'id' => esc_attr( $id ), 'from' => intval( $from ), ) ); } elseif ( ! empty( $to ) ) { $query->set( 'relationship', array( 'id' => esc_attr( $id ), 'to' => intval( $to ) ) ); } } } add_filter( 'query_vars', 'rel_add_query_vars' ); /** * Add query vars to build query with URL parameters * * @param array $vars WP_Query variables. * @return array * @since 3.6.8 */ function rel_add_query_vars( array $vars ) { $vars[] = 'relation_id'; $vars[] = 'relation_from'; $vars[] = 'relation_to'; return $vars; } add_action( 'mb_relationships_init', function() { MB_Relationships_API::register( array( 'id' => 'practices_to_persons', 'from' => array( 'object_type' => 'post', 'post_type' => 'practice', 'admin_column' => 'after title' ), 'to' => array( 'object_type' => 'post', 'post_type' => 'person', 'admin_column' => 'after title', ), ) ); } );October 26, 2018 at 3:46 AM in reply to: ✅pre_get_posts to get all posts connected to single object #11766Content Pilot
Participant

October 26, 2018 at 2:23 AM in reply to: ✅pre_get_posts to get all posts connected to single object #11765Content Pilot
ParticipantI am following the video EXACTLY and am still seeing errors. OMG this is so frustrating. Your video is perfect and is not throwing errors. I setup the freshest install and just installed metabox and mb relationships with custom post types built all in the same file. Made the relationships and ran the query on the default theme like your video. Still seeing the post type being stripped for certain functions like get_post_type_object. I actually think get_post_type_object is returning null since the post type is being sent as a string not an array or object. Is_scalar is exiting early for get_post_type_object.
See the screenshots. I am getting the exact same query you producing with post type being sent as a string.
Running WP 4.9.8 on Flywheel
MySQL 5.6.34
PHP 7.2 and 7.0.3
Nginx
Twenty Seventeen themeCould that have anything to do with it?
October 25, 2018 at 11:08 PM in reply to: ✅pre_get_posts to get all posts connected to single object #11762Content Pilot
ParticipantAwesome video. Thank you so much for going into so much detail. This is exactly what I am after.
I could have sworn that I saw errors on the default theme. I might have some rogue pre get posts that I need to sort out in my main plugin that is also housing the relationship fields. I will do some more digging and report back.
October 23, 2018 at 3:25 AM in reply to: ✅pre_get_posts to get all posts connected to single object #11717October 23, 2018 at 3:24 AM in reply to: ✅pre_get_posts to get all posts connected to single object #11716Content Pilot
ParticipantOctober 23, 2018 at 3:22 AM in reply to: ✅pre_get_posts to get all posts connected to single object #11715Content Pilot
ParticipantStill not working even thought changed how I am getting the query_var.
Did you try running that code a post type archive? That is what I am doing and seeing part of the query being altered. Its weird. It shows the proper post type objects but doesnt have the proper values for sending the post type to things like post_type_archive_title.
Content Pilot
ParticipantThe other thing I noticed is that if you change the post title, then resave, that post gets pushed to the bottom of the related pages list.
Content Pilot
ParticipantDid some testing and found that when I arrange the relationships on a bi-directional relationship, you cannot have a specific sort order on both sides of the relationship.
In my use case, I have an attorney related to a practice area. I want a specific order on the practice area page and then another order of relationships when viewing the attorney biography.
It might be good to add to_order and from_order database column so that you can arrange relationships independently of each other. You could keep the default order to be ID unless filtered to use the from_order or to_order column.
October 20, 2018 at 11:37 PM in reply to: ✅pre_get_posts to get all posts connected to single object #11694Content Pilot
ParticipantI disabled every plugin and reverted to default WP theme to test. I am still stumped. Have a look at the two screenshots. First one is the base query where the query and query_vars match. This query assigns the post type to every other function to get things like post type archive title, etc.
Second is when the query_vars are used to alter the query. Notice how the query and query vars are different. The filtering of posts works great to show only the post that is related to 2735.
Can you add this code to your install and let me know if you are seeing the same errors?
add_action( 'parse_query', 'poa_filter_query_by_relationship', 10, 1 ); /** * Filter the main query by using URL parameters * * @param object $query WP_Query. * @return object * * @since 3.6.8 */ function poa_filter_query_by_relationship( $query ) { $id = get_query_var('relation_id'); $from = get_query_var('relation_from'); $to = get_query_var('relation_to'); if ( ! empty( $id ) && ! is_admin() && $query->is_main_query() ) { if ( ! empty( $from ) ) { $query->set( 'relationship', array( 'id' => esc_attr( $id ), 'from' => intval( $from ), ) ); var_dump($query); } elseif ( empty( $to ) ) { $query->set( 'relationship', array( 'id' => esc_attr( $id ), 'to' => intval( $to ) ) ); } } }add_filter( 'query_vars', 'add_query_vars' ); /** * Add query vars to build query with URL parameters * * @param array $vars WP_Query variables. * @return array * @since 3.6.8 */ public function add_query_vars( array $vars ) { $vars[] = 'relation_id'; $vars[] = 'relation_from'; $vars[] = 'relation_to'; return $vars; }October 18, 2018 at 10:13 PM in reply to: ✅pre_get_posts to get all posts connected to single object #11664Content Pilot
ParticipantOn second look,
parse_queryis throwing off the entire query so the post type archive doesn't even get the post type it is associated with. I am getting the proper related post just fine but I am loosing the post type for the entire query. It seems like I am overriding my entire query and just setting the relationship query instead of adding the two queries together. -
AuthorPosts