Thread Starter
neweb
(@neweb)
I’ve managed to get the following code to work.
<?php
$type = 'post';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 1,
'caller_get_posts'=> 1,
'meta_key' => 'box',
'meta_value' => '1'
);
$my_query = new WP_Query($args);
if ( $my_query->have_posts() )
while ( $my_query->have_posts() ) :
$my_query->the_post(); ?>
I’d like to change the following part so that it points to a category and not a meta key
'meta_key' => 'box',
'meta_value' => '1'
The idea is that the post will go to the relevant box based on its category. Any idea how to do this with the above code!
wp_query has category parameters:
http://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Category_Parameters
example:
$cat_id = 27; //whatever category id you need
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 1,
'caller_get_posts'=> 1,
'category__in' => array($cat_id)
);
Thread Starter
neweb
(@neweb)
This is getting so frustrating. I’m only new to php and I’m really trying my best to get this working and to understand it. The codex has no working examples of what you need in the page. Every time I try a bit of code I get nothing on the page. The codex is not very clear for beginners.
I took the code out and replaced it with the following.
<?php
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li>';
the_title();
echo '</li>';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
This is the code on the entire page. Its a custom template that I want to use on my home page and I want to edit the page to change the up most information on the fly while the 4 boxes change as a new post is added to a category.
[Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]
Frankly I’m loosing all hope in the codex pages as I have never got anything to work after studying them.
Everything I add to the completely custom design is taking 3-4 days to get working and I’m getting so frustrated with it now.
Thread Starter
neweb
(@neweb)
alchymyth
I used your code and it’s displaying the posts as expected.
Thanks for the code.
Now I have a working model I can play around with it.