Retrieve relationships with get_posts()?

Support MB Relationships Retrieve relationships with get_posts()?Resolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12716
    DougDoug
    Participant

    Is it possible to use get_posts() to retrieve relationships instead of WP_Query()? Does the relationship argument need to be modified in some way?

    I’m running into an issue where either WP_Query() or wp_reset_postdata() is causing problems with other functionality. So I tried switching WP_Query() to get_posts() using the same arguments, but I get an empty array when I do that.

      $args = array(
        'relationship' => array(
          'id' => 'design_to_product',
          'to' => get_the_ID(),
        ),
        'nopaging' => true
      );
      // Query
      $related_designs = get_posts($args);
      print_r($related_designs);
    #12727
    FarheenFarheen
    Participant

    Hello Doug

    It is not possible to retrieve relationships with get_posts() due to restrictions

    get_posts() is very similar in usage and accepts the same arguments (with some nuances, like different defaults), but returns an array of posts, doesn't modify global variables and is safe to use anywhere.

    WP_Query is the class that powers both behind the scenes, but you can also create and work with your own instance of it. A bit more complex, fewer restrictions, also safe to use anywhere.

    WP_Query Functions

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