0

I'd like the script to return a list of posts which are in the category 'team-resources' and also have the custom field value for Hub ID which the script finds on the page.

If the page carries a value for "Hub ID" of Hub1, the script would return a list of all pages with custom value Hub1 which are also in the category 'team-resources'

If the script runs on a page that has a value of Hub2 in custom field, it would return a list of all pages with Hub2 which are also in the cateogry 'team-resources'.

Many thanks to iambriansreed who helped me get this far and was very helpful. It was my error that keeps me coming back.

Any help much appreciated, wh

function hubs_resources_posts() {
    global $post;

    $hub_resources_posts = get_posts( array( 

        'post__not_in' => array( $post->ID ), 
        'category_name' => 'team-resources',
        'meta_key' => 'Hub ID', 
        'meta_value' => get_post_meta( $post->ID, 'Hub ID', 1 ) 
    ) );

    $output = '<ul>';
    foreach ( $hub_resources_posts as $hub_resources_post ) {
        $output .= '<li><a href="' . get_permalink( $hub_resources_post->ID ) . '">' . 
            apply_filters( 'the_title', $hub_resources_post->post_title, $hub_resources_post->ID ) .            
            '</a></li>';
    }
    $output .= '</ul>';

    return $output;
}
  • What's the question? How is it not working? – TheDeadMedic Feb 5 '15 at 11:12
  • I created a field "Hub ID" and put Hub1 as a value. I created several similar pages in the category 'team-resources' but they don't show up on a list of links. I assume I must have mis-adapted the code generously offered by iambriansreed. I played with it for some time but unable to get the proper result. If the code looks perfect I'll try some more. Thanks. – Warm Heart Feb 5 '15 at 13:13
  • I am pretty sure the actual meta_key isn't Hub ID but something like Hub_ID or something like that. – iambriansreed Feb 5 '15 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.