WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Need advice on how I should fix my $params (3 posts)

  1. senyoraangelica
    Member
    Posted 12 months ago #

    I have a custom post type, BOOKS. It has several custom fields, namely; TITLE, AUTHOR, GENRE, RATING. I need advice on how to fix my code below so that only books that have the search word in the custom fields; title, author, genre; WITH EXACTLY the rating specified in my search form, gets displayed in the results?

    I have made a custom search form; a text area that will search through the title, author, and genre; and a dropdown that will match the rating. The code in my params below only searches through the title, author, and genre. But I am now stumped in how to add the code for the rating.

    This is how I visually imagined it: (title OR author OR genre) AND rating.

    $params = array(
        'orderby' => $sortbooks,
        'limit' => 5,
        'search' => false,
        'where' => array(
            'relation' => 'OR',
              array(
                 'key' => 'title',
                 'value' => $searchvalue,
                 'compare' => 'LIKE'
              );
              array(
                 'key' => 'author',
                 'value' => $searchvalue,
                 'compare' => 'LIKE'
              );
              array(
                 'key' => 'genre',
                 'value' => $searchvalue,
                 'compare' => 'LIKE'
              );
    ),
            array(
            'relation' => 'AND',
              array(
                 'key' => 'rating',
                 'value' => $ratingvalue,
                 'compare' => '=',
                 'type' => 'NUMERIC'
              ));

    I would extremely appreciate your help and advice.

    http://wordpress.org/plugins/pods/

  2. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 12 months ago #

    Try this:

    $params = array(
    	'orderby' => $sortbooks,
    	'limit' => 5,
    	'search' => false,
    	'where' => array(
    		'relation' => 'AND',
    		array(
    			'relation' => 'OR',
    			array(
    				'key' => 'title',
    				'value' => $searchvalue,
    				'compare' => 'LIKE'
    			),
    			array(
    				'key' => 'author',
    				'value' => $searchvalue,
    				'compare' => 'LIKE'
    			),
    			array(
    				'key' => 'genre',
    				'value' => $searchvalue,
    				'compare' => 'LIKE'
    			)
    		),
    		array(
    			'key' => 'rating',
    			'value' => $ratingvalue,
    			'compare' => '=',
    			'type' => 'NUMERIC'
    
    		)
    	)
    );
  3. senyoraangelica
    Member
    Posted 12 months ago #

    That worked perfectly! Thank you!!! You're the best!!!

Reply

You must log in to post.

About this Plugin

About this Topic