Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Created March 3, 2015 20:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc0ttkclark/c9d96afd3135879864d5 to your computer and use it in GitHub Desktop.
Save sc0ttkclark/c9d96afd3135879864d5 to your computer and use it in GitHub Desktop.
Example from PodsCast 1
<?php
////////////////
// User Example
////////////////
$user = pods( 'user' ); // User
$params = array(
'orderby' => 't.user_login',
'limit' => 10,
'where' => '
(
favorite_animal.post_title = "Elephant" OR
favorite_animal_custom.meta_value = "Elephantus"
) AND
favorite_animal.related_animals.color.meta_value = "Green"
'
);
$user->find( $params );
// Loop through all users
while ( $user->fetch() ) {
echo '<p>' . $user->display( 'display_name' ) . '</p>';
}
////////////////
// CPT Example
////////////////
$event = pods( 'event' ); // CPT
// Get it from a variable
$series = 'Jim True Presents';
$params = array(
// t = wp_posts
'where' => '
t.post_title = "X" OR
t.post_name = "x" OR
t.ID = 123 OR
my_custom_field.meta_value = "Some value" OR
speaker.post_title IN ( "Jim", "Phil", "Josh", "Scott" ) OR
speaker.speaker_series.post_title = "' . pods_sanitize( $series ) . '"
' // Always sanitize variables going into find()
);
// WP_Query meta_query syntax example for 'where'
$params = array(
// t = wp_posts
'where' => array(
'relation' => 'OR',
array(
'key' => 'post_title',
'value' => 'X'
),
array(
'key' => 'post_name',
'value' => 'x'
),
array(
'key' => 'my_custom_field',
'value' => 'Some value'
),
array(
'key' => 'speaker.post_title',
'value' => array(
'Jim',
'Phil',
'Josh',
'Scott'
),
'compare' => 'IN'
// Other options for 'compare' (same as WP_Query meta_query supports)
// 'compare' => '=',
// 'compare' => '!=',
// 'compare' => '>',
// 'compare' => '>=',
// 'compare' => '<',
// 'compare' => '<=',
// 'compare' => 'LIKE',
// 'compare' => 'NOT LIKE',
// 'compare' => 'IN',
// 'compare' => 'NOT IN',
// 'compare' => 'BETWEEN',
// 'compare' => 'NOT BETWEEN',
// 'compare' => 'EXISTS',
// 'compare' => 'NOT EXISTS',
),
array(
'key' => 'speaker.speaker_series.post_title',
'value' => 'Jim True Presents'
)
)
);
$event->find( $params );
////////////////
// Other Pods
////////////////
$comment = pods( 'comment' ); // Comments
$category = pods( 'category' ); // Taxonomy
$author = pods( 'author' ); // Advanced Content Type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment