Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is my code, why cant i get post per page and offset result ?.

<?php 
    $myquery['tax_query'] = array(
        'relation' => 'OR',
        'posts_per_page' => 3,
        'offset' => 3,
    array(
        'taxonomy' => 'brands',
        'terms' => array('iHOME'),
        'field' => 'slug',
        ));
    query_posts($myquery);?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_post_thumbnail();?>
<b><?php the_title();?></b>
<p><?php echo excerpt(25); ?></p>
<?php echo esc_html( get_post_meta( get_the_ID(), 'category', true ) ); ?>

<?php endwhile; else: ?>
<?php endif; ?>
share|improve this question
    
it's <?php not >?php –  JMau Jun 30 '13 at 12:50
    
@ShihabMalayil here is your solution: MARKDOWN HELP. Please, get into a habit to write your questions nicely. –  Eugene Manuilov Jun 30 '13 at 13:06
    
@Eugene Manuilov- THANK YOU –  Shihab Malayil Jun 30 '13 at 13:12
add comment

1 Answer

Your query args are messed up. Posts per page and offset params are not part of the tax_query array. Check out the example in the Codex: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

$args = array( 
    'post_type' => array('your_cpt'),
    'posts_per_page' => 3,
    'offset' => 3,
    'tax_query' => array(
       'relation' => 'OR',
        array(
            'taxonomy' => 'brands',
            'terms' => array('iHOME'),
            'field' => 'slug',
            )
    ) 
);

$tax_query = new WP_Query($args);

if ( $tax_query->have_posts() ) : while ( $tax_query->have_posts() ) : $tax_query->the_post(); 

    the_post_thumbnail();
    the_title();
    echo excerpt(25); 
    echo esc_html( get_post_meta( get_the_ID(), 'category', true ) ); 

endwhile; else: 
endif; 

wp_reset_postdata();

Also, I couldn't really explain why, but I always see it written around here to avoid using query_posts, so I replaced that in my answer with new WP_Query.

One more thing, if you are querying for a post type other than posts, you'll need to define the post_type query parameter.

share|improve this answer
    
sure, it's CPT. -Thank you- –  Shihab Malayil Jun 30 '13 at 14:04
    
@helgatheviking- You are correct. 'tax_query' => array( . thank you very much. expecting more....! –  Shihab Malayil Jun 30 '13 at 14:11
    
What are you expecting more of? The code should work now. –  helgatheviking Jun 30 '13 at 14:14
    
iam sorry, i mean help me next time. thank you. tax_query' => array( ,you just missed =>. –  Shihab Malayil Jun 30 '13 at 14:16
    
We'll see. I'm only on here some of the time. Fixed the typo. Don't forget to mark as resolved if this solves your question. –  helgatheviking Jun 30 '13 at 14:25
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.