Support

Account

Home Forums Front-end Issues get_posts by Post Object not returning results

Solved

get_posts by Post Object not returning results

  • Hello,

    I have been working on returning a list of custom post objects based on a custom Post Object field value and I can’t seem to figure out why it is returning an empty array.

    My code is as follows:

     
      $post_id = $_GET['post'];
      $videos = get_posts(array(
       'post_type' => 'video-clip',
       'meta_query' => array(
        array(
          'key' => 'parent_location',
          'value' => '"' . $post_id . '"',
          'compare' => 'LIKE'
           )
         )
       )); 

    I have confirmed that there are two video-clip posts which have the correct post selected within the parent_location field in admin editor, but when I var_dump my return value its coming back with array(0) { }

    It is probably something very obvious, but I haven’t been able to figure it out so hoping someone here can point me in the right direction.

    Thanks,
    Tristan

  • Update: It turns out that the Post Object field is not saving the post ID so there isn’t anything wrong with the query! Now to figure out why the post ID isn’t being saved!

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

The topic ‘get_posts by Post Object not returning results’ is closed to new replies.