Forum Replies Created
-
AuthorPosts
-
Olivier
ParticipantEDIT: as for the New > Relationships submenu, a Contributor cannot actually create a new relationship. It leads to a page with the only option to add a
TitleandSubmit for Review. So at least they're not able to create new relationships -- but it's also a completely useless and potentially confusing menu, so I'd love to remove itOlivier
ParticipantSure thing, in fact I can paste the generated PHP code for the relationship:
<?php add_action( 'mb_relationships_init', 'your_prefix_function_name' ); function your_prefix_function_name() { MB_Relationships_API::register( [ 'id' => 'user-provider', 'from' => [ 'object_type' => 'user', 'post_type' => 'licensee', 'taxonomy' => 'category', 'empty_message' => 'Not affiliated with a Provider', 'admin_column' => [ 'position' => 'after title', 'title' => 'Affiliation', 'link' => 'view', ], 'meta_box' => [ 'title' => 'Provider you\'re affiliated with', 'context' => 'normal', 'style' => 'seamless', ], ], 'to' => [ 'object_type' => 'post', 'post_type' => 'licensee', 'admin_column' => [ 'position' => 'after title', 'title' => 'Affiliated', 'link' => 'view', ], 'meta_box' => [ 'title' => 'User accounts associated with this licensee', 'context' => 'normal', 'priority' => 'high', ], 'field' => [ 'name' => 'Affiliated Licensee', ], ], ] ); }But if you want a screenshot from the UI here is one https://imgur.elightup.com/vYJ3QdK.png
Olivier
ParticipantViews already offers the
{{ author.ID }}variable, why can't I use that? I tried it and it makes the whole page break.That said, to verify the code is working in the first place I replaced
UserIDwith the value7(user ID of the author of a post I'm testing the View on) and it's still not showing anything...Are you sure the code you provided is sound?
Olivier
ParticipantEdit: you'll see post-type declared as
licenseeabove instead ofprovider. Ignore that - I was trying it because I use a slug rewrite. But the result is the same with both.Olivier
ParticipantPeter,
I appreciate your answer, unfortunately it's not working.
Would it be an issue with
from: UserID? I wonder if it should be something else since I need providers connected to the post author, not the current logged in user visiting the page.Here is the View I created with your input:
{% set args = { post_type: 'licensee', relationship: { id: 'user-provider', from: userID } } %} {% set posts = mb.get_posts( args ) %} {% for post in posts %} <a href="{{ post.url }}"> <div class="mb-container related-provider provider-related-to-user"> <div class="provider-logo"> {% set field = attribute( post, '_thumbnail_id' ) %} {% for item in field %} <img src="{{ item.medium.url }}" alt="{{ item.medium.alt }}"> {% endfor %} </div> <div class="provider-name"> <span>{{ post.title }}</span> </div> </div> </a> {% endfor %}April 17, 2023 at 4:03 AM in reply to: Fields from related post(s) do not show in 'View' of Custom Post Type #41513Olivier
ParticipantI was looking to do the same thing and the code above, although adapted to my variables, doesn't work. Was anyone ever able to make this work? I have yet to find a post on this forum where someone says they've been able pull data from a relationship into a query.
Olivier
Participant"Exclude from search" worked! thank you
Olivier
ParticipantHi Peter,
I'm not sure I understand your question. The taxonomy archive is in the typical locations automatically created by WordPress for any taxonomy, i.e. http://www.site.com/taxonomy_name_slug/taxonomy_term_slug
I have already disabled archives for the CPT in question, and that works fine. But that CPT still shows up on the archives of the taxonomy (along with another post types), and I would like this specific CPT *not* to appear in the archives of that taxonomy.
Does it make sense?
Olivier
ParticipantNevermind, I found how to do it by checking off "Public queryable" in the Advanced options for that taxonomy.
January 5, 2023 at 11:19 AM in reply to: ✅Insert connected post title for current item in a Query Loop #40125Olivier
ParticipantThanks Peter, but as far as I understand, that function is a normal WordPress function, not specific to GenerateBlocks - or am I wrong?
I'm not understanding why this code is not working:
add_filter( 'render_block', function( $block_content, $block ) { if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'licensee-name' ) !== false ) { $myreplace1 = 'placeholder'; $hol_licensee_name = MB_Relationships_API::get_connected( [ 'id' => 'licensee-events', 'to' => get_the_ID(), ] ); $block_content = str_replace( $myreplace1, $hol_licensee_name , $block_content ); } return $block_content; }, 10, 2 );Can you help?
Olivier
ParticipantPeter, it works thank you so much! I've been struggling with this for weeks!
Can you clarify what you mean by "You can pass object ID or full object"? I understand object ID, but what is "full object"? Do you mean the object ID, and any content field within it?
Olivier
ParticipantHa! That's exactly what I needed - I figured it out thank you!
Here is an example screenshot for anyone looking for something like this in the future: https://imgur.elightup.com/ABmJ0xy.png
Olivier
ParticipantHi Peter,
I'm not sure how to find/share the code for the query, it is generated by the GenerateBlocks Pro plugin. That's why I don't know how to pass
relationshipparameters to it, and the documentation is not helping me (I see the documentation, I just don't know how to use it for my use-case).However I can share the code I'm currently using to filter the query based on a custom field (using Metabox' "Post" custom field to mimic a relationship):
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'only-provider-events' ) !== false ) { return array_merge( $query_args, array( 'meta_query' => array( array( 'key' => 'event_host', 'value' => get_the_ID(), 'compare' => '=', ) ) ) ); } return $query_args; }, 10, 2 );Can I tweak this code snippet to pass
relationshipparameters?If I can get this to work, I'll be happy to go publish the solution on the GeneratePress/GenerateBlocks forums, as I know I'm not the only one struggling with this.
Olivier
ParticipantThank you. And if I want to filter a Query Loop by some fields of a related post, would I use the code described in https://docs.metabox.io/extensions/mb-relationships/#post-archive ?
Olivier
ParticipantThank you Peter, even just that is incredibly more useful than the documentation.
And to clarify, I would put this code in my template file, right?
-
AuthorPosts