Scott Kingsley Clark is the lead developer of Pods, a senior web engineer at 10up, a top WordPress development agency, and has more than ten years of experience in web development, primarily using WordPress. In this talk he'll share some of the lesser known functions and capabilities of Pods and WordPress that you should know about in order to take your WordPress development to the next level.
4. Manipulating field Pods data with add_to / remove_from
$pods = pods( 'article', 345 );
$pods->add_to( 'category', 123 ); // Relationship fields (add 123 to list)
$pods->add_to( 'count', 1 ); // Number fields (+1)
$pods->add_to( 'next_date', '+5 days' ); // Date fields (add time to field)
$pods->add_to( 'post_content', "nnMore text to add to this field.." ); // Text fields (append text to
content)
$pods->remove_from( 'category', 123 ); // Relationship fields (remove 123 to list)
$pods->remove_from( 'count', 1 ); // Number fields (-1)
$pods->remove_from( 'next_date', '-5 days' ); // Date fields (remove time to field)
Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014
5. Checking against values of Pods fields while in loops with is / has
$pods = pods( 'article', array( 'limit' => 25 ) );
while ( $pods->fetch() ) {
// Check if count === 14
if ( $pods->is( 'count', 14 ) ) {
echo 'Counting is... AWESOME!';
}
// Check if next_date === 10/03/2014
elseif ( $pods->is( 'next_date', '10/03/2014' ) ) {
echo 'Dates are... AWESOME!';
}
// Check if post_content === 'N/A'
elseif ( $pods->is( 'post_content', 'N/A' ) ) {
echo 'Content is... AWESOME!';
}
}
while ( $pods->fetch() ) {
Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014
// Check if category has 123 (even if multiple set)
if ( $pods->has( 'category', 123 ) ) {
echo 'I can haz category 123!';
}
// Check if post_content contains 'OMG'
elseif ( $pods->has( 'post_content', 'OMG' ) ) {
echo 'I can haz OMG!';
}
}
6. Pods Media Functions and wp_prepare_attachment_for_js
echo pods_image(
$pods->field( 'thumbnail' ), // Image ID, guid, or field value array
'thumbnail', // Image size to get <img> for
123 // Default if arg 1 is empty
);
// Import an attachment, give it a post parent if needed, and maybe set as featured image
$attachment_id = pods_attachment_import( $url, $post_parent, $featured );
// Resize an image on demand to any specific size
// in string or array( 'width' => 100, 'height' => 150, 'crop' => false ) format
$success = pods_image_resize( $attachment_id, $size );
// Get EVERYTHING from an attachment, width, height,
// size array with every bit of info you could ever dream of
$attachment_data_zomg = wp_prepare_attachment_for_js( $attachment_id );
Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014