Support » Plugin: Custom Content Type Manager » search post on custom fied

  • Hello,

    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 !

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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);
    Plugin Contributor fireproofsocks


    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:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘search post on custom fied’ is closed to new replies.