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.

I need to filter my posts in categories pages, by showing only posts that have specific WORD in custom field value. I need php code that i should add in loop for this category.

Details: I need loop query that will say - show posts in this category (crocs) only if custom field hey 'brand' contain the same value (crocs). BUT note, in custom field 'brand' i have more brands, for example 'diesel, crocs, fendi'. Now i need post to show if value contains crocs, not if it's equal to crocs (as other brands can be present).

Thanks a lot for your help. Maybe this is basic, but I am noob and trying to learn and understand WP :)

Cheers, Dean

share|improve this question
    
could i do something like - show posts if cat_title exist in meta_value???: <?php query_posts('meta_key=Brand&meta_value=*single_cat_title();*'); ?> <?php get_template_part( 'loop' , 'entry') ?> –  Dean Sep 1 '12 at 4:34

1 Answer 1

args = array(
    'post_type' => 'product',
    'meta_query' => array(
        array(
            'key' => 'brand',
            'value' => 'crocs',
            'compare' => 'LIKE'
        )
    )
 );
$query = new WP_Query( $args );

http://codex.wordpress.org/Class_Reference/WP_Query

share|improve this answer

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.