Get connected post

Support MB Relationships Get connected postResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15104
    Max@powdersky.com[email protected]
    Participant

    Hi,

    Is there a way I can get a connected post without haven't to query it?

    For example I have a connection between resorts and accommodation so if I am on the accommodation page I want to display a link to the resort page, I know I could use the WP_Query but wondered if I could use something a bit more simpler?

    i.e get_connected_post_id() EXAMPLE

    Thanks

    #15133
    Anh TranAnh Tran
    Keymaster

    Hi Max,

    You can do raw SQL query like this:

    global $wpdb;
    $ids = $wpdb->get_col( "SELECT <code>to</code> FROM $wpdb->mb_relationships WHERE <code>from</code> = 123 AND <code>type</code> = 'your_relationship' ");

    PS: I think WP_Query is fine if you set 'fields' => 'ids'.

    #15144
    Max@powdersky.com[email protected]
    Participant

    Thanks Anh, didn't realize you could use 'fields', neat trick thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.