Custom Content Type Manager
search post on custom fied (3 posts)

  1. jpprade
    Posted 2 years ago #


    I am new with both word press and cctm which is great and save me a lot of work. Thanks a lot for building this plug in !

    I have a custom type called Item which has a price.
    Now I wanted to search Post depending on some cutom field. For instance on the "Price" field and I would like to search for every post which price is higher or lower than a posted value.

    if I do that :
    $Q = new GetPostsQuery();
    $args = array();
    $args['post_type'] = 'item';
    $args['orderby'] = 'post_title';
    $args['price'] = '10';
    $results = $Q->get_posts($args)

    it will return items where price equals 10.

    Could you point me out a link or a quick sample code, how to achieve that. If I could avoid writting sql it would be good, if it is not possible I ll deal with it.

    thanks !


  2. jpprade
    Posted 2 years ago #

    Ok after googling with some better keyword I found an answer :

    $args = array(
    	  'post_type'=> 'item'
    $args['meta_query']= array(
    		'key' => 'price',
    		'value' => 10,
    		'type' => 'numeric',
    		'compare' => '<'
    $results = query_posts($args);
  3. fireproofsocks
    Plugin Author

    Posted 2 years ago #

    You can use query_posts if you want, but I found it to be maddeningly poorly conceived due to reliance on global variables and WP's incessant habit of having unseen hooks in everything. That and WP_Query were the biggest motivators in me writing my own database API which became the GetPostsQuery class.

    To use GetPostsQuery to the same effect, you could modify your original query like this:

    $Q = new GetPostsQuery();
    $args = array();
    $args['post_type'] = 'item';
    $args['orderby'] = 'post_title';
    $args['price']['>'] = '10';
    $results = $Q->get_posts($args)

    Take a look at the wiki, specifically at the operators that are supported by GetPostsQuery: http://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_posts#Operators

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Content Type Manager
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic