WordPress.org

Support

Support » Plugins and Hacks » Custom Content Type Manager » [Plugin: Custom Content Type Manager] get_posts_sharing_custom_field_value

[Plugin: Custom Content Type Manager] get_posts_sharing_custom_field_value

  • Hello,

    The following is yielding code the right post IDs that Im after. However, its just spitting out ‘87513’ when I really need the following: array(8, 75, 13). I need to use the output in a WP query.

    <?php
    $projectposts = get_posts_sharing_custom_field_value(‘program’, ‘A360’);
    foreach ($projectposts as $p) {
    echo $p[‘ID’];
    }
    ?>

    Thanks!

    Jay

    http://wordpress.org/extend/plugins/custom-content-type-manager/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor fireproofsocks

    @fireproofsocks

    Yep, your code is just printing out the values, one right after the other. If you want an array, you have to feed the values into an array.

    <?php
    $projectposts = get_posts_sharing_custom_field_value('program', 'A360');
    $my_array = array();
    foreach ($projectposts as $p) {
        $my_array[] = $p['ID'];
    }
    print_r($my_array); // <-- now the values are in an array
    ?>
    Plugin Contributor fireproofsocks

    @fireproofsocks

    Actually… the more I think about this… you’ve already DONE a query. Full disclosure: I loathe WP_Query (which is one of the main reasons I wrote the Summarize Posts plugin and the integrated GetPostsQuery class) so take this with a grain of salt. By running get_posts_sharing_custom_field_value() you already have all the information about those posts — every field in them, including the custom fields. Why would you need to do another query just to retrieve some of the same information you already have?

    Thanks so much for the help. I fear I lack some php fundamentals. (Its really easy to find super basic php instruction or very advanced stuff. The intermediate stuff is under explained.)

    Here’s why I was thinking I needed to do the query:

    My user’s make posts associated with a to a ‘Project’ post type.
    Projects are mapped to a Program value (custom field)

    I needed to show all the posts for all projects associated with a program. So I was trying to get all the project ID’s associated with a program. Then I’m feeding that array of project ID’s into a WP_querry to return the posts.

    Is there a better way?

    Again, thanks greatly!

    Plugin Contributor fireproofsocks

    @fireproofsocks

    That’s what I’m saying: you ALREADY RETURNED THE POSTS. You’re adding an unnecessary step. get_posts_sharing_custom_field_value() returns the posts already.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Custom Content Type Manager] get_posts_sharing_custom_field_value’ is closed to new replies.
Skip to toolbar