Custom Fields
Re-Envisioned
Support MB Relationships Get connected post

This topic contains 2 replies, has 2 voices, and was last updated by  Max@powdersky.com 2 months, 3 weeks ago.

  • Creator
    Topic
  • #15104
    Resolved
    Max@powdersky.com
    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #15133

    Anh 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
    Participant

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

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.