jeudi 5 février 2015

Php custom query function assistance


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;


}





Aucun commentaire:

Enregistrer un commentaire