Adding External Variable to An Array
-
Here is what I’m trying to accomplish:
$cat_id = get_post_meta($post_id, ‘category’, ‘true’);
$args = array( ‘numberposts’ => 5,’category’ => $cat_id );
$myposts = get_posts( $args );In layman’s terms, I want to pull the value of the category ID from a post custom field. Then add that field into the argument array to dynamically display posts in the sidebar on a page depending on what category ID they used in the post. Each time I do this it displays all of my posts and then the last post is displayed as content in the main section of my site. Should $cat_id be initialized a different way?
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Adding External Variable to An Array’ is closed to new replies.