Hi, I’ve hacked my WordPress template lots. I want to pass a variable from the custom field to a WP_Query.
First I get the variable from the custom field my_cat
$my_cat = get_post_meta($post->ID, 'my_cat', true);
Then I want to pass $my_cat to this query below
$archive_query = new WP_Query('showposts=9999&cat=&my_cat'); // this isn't working
while ($archive_query->have_posts()) : $archive_query->the_post();
.. do stuff ..
<?php endwhile; ?>
Basically what i’m trying to do is to filter posts by category. I define the category ID in $my_cat through a custom field (call it ‘n’). Then I want to pass it as an argument to WP_Query as cat=n, where n equals $my_cat.
Thanks in advance.
- The topic ‘How to pass this variable? PHP kung-foo masters please help’ is closed to new replies.