How to get all posts with a meta key? (2 posts)

  1. imjscn
    Posted 5 years ago #

    I have a group of data saved in post meta. One of the meta key is "project_id", if a post meta has this key, that means this post include a project.

    Now I want to get all post that with the meta key of "project_id", so that I can make a loop for it.

    I tried this

    $meta_key = 'project_id';
    return $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key));

    It returns nothing.
    Please help! Thanks!

  2. esmi
    Forum Moderator
    Posted 5 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic