Relationships search functionality
Support › MB Relationships › Relationships search functionality
- This topic has 4 replies, 3 voices, and was last updated 5 months ago by
Eliodata.
-
AuthorPosts
-
February 1, 2024 at 5:14 PM #44450
Eliodata
ParticipantHello, I'm using the MB Relationships extension to link a custom post type with WordPress users. The metabox on the cpt edit page allows selecting users through a dropdown, which currently searches by first and last names. However, I'd like to enhance this search functionality to include the 'billing_company' field as well, so the dropdown displays 'billing_company first_name last_name' instead of just 'first_name last_name'. How can I achieve this? The ID of the MB Relationship field is 'clients-wp-bdd'
regards
February 1, 2024 at 10:56 PM #44454Peter
ModeratorHello,
Currently, the relationship extension doesn't support an option or a filter hook to adjust the search result and display items. I will inform the development team to explore the possibility.
Thank you.
February 2, 2024 at 12:22 AM #44455Eliodata
ParticipantThank you for the quick answer. Hope they will find something.
If you give some clues maybe I could on my side.
Best regardsNovember 13, 2024 at 5:05 AM #46919Markus Millendorfer
ParticipantHi, is there a plan to add this functionality.
I have a post type with 500 entries (business location) - some of them with similar names but different address - so the relation field can not be used by us, as you never know which item gets selected in such cases.November 13, 2024 at 3:39 PM #46922Eliodata
ParticipantHi,
I finally use this snippet to display a metabox in my cpt with a link to the related user. The link display the billing company field, but you can use any other user field.
// MODIFIER AFFICHAGE CHAMP relationnel clients-wp-bdd METABOX.IO cote BDD clients add_action( 'add_meta_boxes', 'add_link_to_wp_user_meta_box' ); function add_link_to_wp_user_meta_box() { add_meta_box( 'link_to_wp_user_meta_box', // ID unique 'Lien vers le compte utilisateur WP', // Titre de la metabox 'display_link_to_wp_user_meta_box', // Fonction callback pour afficher le contenu 'client', // Le CPT auquel cette metabox est liée 'side', // Position de la metabox 'high' // Priorité de l'affichage ); } function display_link_to_wp_user_meta_box( $post ) { global $wpdb; // Récupérer l'ID de l'utilisateur associé au CPT via la relation 'clients-wp-bdd' $client_id = $post->ID; $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT <code>from</code> FROM {$wpdb->prefix}mb_relationships WHERE <code>to</code> = %d AND <code>type</code> = 'clients-wp-bdd'", $client_id )); if ( !empty( $user_id ) ) { // Récupérer les informations de l'utilisateur WP $user = get_userdata( $user_id ); $billing_company = get_user_meta( $user_id, 'billing_company', true ); $edit_link = get_edit_user_link( $user_id ); // Afficher un lien cliquable vers la page d'édition de l'utilisateur WP if ( !empty( $billing_company ) ) { echo '<p>Société : <a href="' . esc_url( $edit_link ) . '">' . esc_html( $billing_company ) . '</a></p>'; } else { echo '<p>Aucun champ "billing_company" trouvé pour cet utilisateur.</p>'; } } else { echo '<p>Aucun utilisateur lié trouvé.</p>'; } }
-
AuthorPosts
- You must be logged in to reply to this topic.