WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. jpprade
    Member
    Posted 1 year ago #

    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 !

    http://wordpress.org/extend/plugins/custom-content-type-manager/

  2. jpprade
    Member
    Posted 1 year ago #

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

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

    Posted 1 year 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

About this Topic