SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
Undercover Pods 
/ WP Functions 
Scott Kingsley Clark, @scottkclark 
Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014
Looping with Pods and zebra / nth 
$params = array( 
'orderby' => 't.created DESC', 
'limit' => 25 
); 
$pods = pods( 'article', $params ); 
?> 
<h2>Latest 25 articles</h2> 
<?php 
while ( $pods->fetch() ) { 
$class = ''; 
if ( $pods->zebra() ) { // Every odd item 
$class = ' class="odd"'; 
} elseif ( $pods->nth( '4n+0' ) ) { // Every fourth item, using nth-child CSS syntax 
$class = ' class="fourth"'; 
} 
?> 
<p><a href="<?php echo esc_url( $pods->field( 'detail_url' ) ); ?>"><?php echo $pods->index(); ?></a></p> 
<?php 
} 
Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014
Filtering lists and grabbing properties with wp_list_filter and wp_list_pluck 
$foods = array( 
Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014 
array( 
'name' => 'Banana', 
'color' => 'Yellow', 
), 
array( 
'name' => 'Apple', 
'color' => 'Red', 
) 
); 
$food_names = wp_list_pluck( $foods, 'name' ); 
// $food_names is now 
$food_names = array( 
'Banana', 
'Apple' 
); 
$foods = array( 
array( 
'name' => 'Banana', 
'color' => 'Yellow', 
), 
array( 
'name' => 'Apple', 
'color' => 'Red', 
) 
); 
$red_foods = wp_list_filter( $foods, array( 'color' => 'Red' 
) ); 
// $red_foods is now 
$red_foods = array( 
array( 
'name' => 'Apple', 
'color' => 'Red', 
) 
);
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
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!'; 
} 
}
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

Contenu connexe

Tendances

YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
Jeremy Kendall
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
Thomas Weinert
 
Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012
Michael Peacock
 

Tendances (20)

YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
solving little problems
solving little problemssolving little problems
solving little problems
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Symfony without the framework
Symfony without the frameworkSymfony without the framework
Symfony without the framework
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
New in php 7
New in php 7New in php 7
New in php 7
 
Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012
 

En vedette

Pictures of different types of limestone
Pictures of different types of limestonePictures of different types of limestone
Pictures of different types of limestone
Heather3673
 
Building Materials for Construction
Building Materials for Construction Building Materials for Construction
Building Materials for Construction
Ajjay Kumar Gupta
 

En vedette (20)

Grow Beyond Posts & Pages: Introduction to the Pods Framework, a Content Mana...
Grow Beyond Posts & Pages: Introduction to the Pods Framework, a Content Mana...Grow Beyond Posts & Pages: Introduction to the Pods Framework, a Content Mana...
Grow Beyond Posts & Pages: Introduction to the Pods Framework, a Content Mana...
 
Cement
CementCement
Cement
 
Pictures of different types of limestone
Pictures of different types of limestonePictures of different types of limestone
Pictures of different types of limestone
 
Properties of Aggregate and cement
Properties of Aggregate and cementProperties of Aggregate and cement
Properties of Aggregate and cement
 
3. lime
3. lime3. lime
3. lime
 
Types of bonds
Types of bondsTypes of bonds
Types of bonds
 
Introduction to dental cements dental material
Introduction to dental cements dental materialIntroduction to dental cements dental material
Introduction to dental cements dental material
 
Limestone
LimestoneLimestone
Limestone
 
Aggregate - Concrete Technology
Aggregate - Concrete TechnologyAggregate - Concrete Technology
Aggregate - Concrete Technology
 
Dental cement dental material
Dental cement dental materialDental cement dental material
Dental cement dental material
 
Properties of aggregrate
Properties of aggregrateProperties of aggregrate
Properties of aggregrate
 
Cement
CementCement
Cement
 
Aggregates of Concrete
Aggregates of ConcreteAggregates of Concrete
Aggregates of Concrete
 
Properties of Cement
Properties of CementProperties of Cement
Properties of Cement
 
Aggregates ppt
Aggregates pptAggregates ppt
Aggregates ppt
 
Stone masonary
Stone masonaryStone masonary
Stone masonary
 
Bamboo construction (final ppt)
Bamboo construction (final ppt)Bamboo construction (final ppt)
Bamboo construction (final ppt)
 
Construction material lime
Construction material limeConstruction material lime
Construction material lime
 
MODALS PPT
MODALS PPTMODALS PPT
MODALS PPT
 
Building Materials for Construction
Building Materials for Construction Building Materials for Construction
Building Materials for Construction
 

Similaire à Undercover Pods / WP Functions

Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
Hari K T
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
chuvainc
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
camp_drupal_ua
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
unodelostrece
 

Similaire à Undercover Pods / WP Functions (20)

What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
Drupal 8 database api
Drupal 8 database apiDrupal 8 database api
Drupal 8 database api
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
PHP API
PHP APIPHP API
PHP API
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Daily notes
Daily notesDaily notes
Daily notes
 
Drupal7 dbtng
Drupal7  dbtngDrupal7  dbtng
Drupal7 dbtng
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
Wp query
Wp queryWp query
Wp query
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
 
Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)
 
JavaScript in Drupal 7: What developers need to know
JavaScript in Drupal 7: What developers need to knowJavaScript in Drupal 7: What developers need to know
JavaScript in Drupal 7: What developers need to know
 
JavaScript in Drupal 7: What developers need to know
JavaScript in Drupal 7: What developers need to knowJavaScript in Drupal 7: What developers need to know
JavaScript in Drupal 7: What developers need to know
 

Dernier

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Dernier (20)

WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 

Undercover Pods / WP Functions

  • 1. Undercover Pods / WP Functions Scott Kingsley Clark, @scottkclark Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014
  • 2. Looping with Pods and zebra / nth $params = array( 'orderby' => 't.created DESC', 'limit' => 25 ); $pods = pods( 'article', $params ); ?> <h2>Latest 25 articles</h2> <?php while ( $pods->fetch() ) { $class = ''; if ( $pods->zebra() ) { // Every odd item $class = ' class="odd"'; } elseif ( $pods->nth( '4n+0' ) ) { // Every fourth item, using nth-child CSS syntax $class = ' class="fourth"'; } ?> <p><a href="<?php echo esc_url( $pods->field( 'detail_url' ) ); ?>"><?php echo $pods->index(); ?></a></p> <?php } Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014
  • 3. Filtering lists and grabbing properties with wp_list_filter and wp_list_pluck $foods = array( Undercover Pods / WP Functions // Scott Kingsley Clark // PodsCamp 2014 array( 'name' => 'Banana', 'color' => 'Yellow', ), array( 'name' => 'Apple', 'color' => 'Red', ) ); $food_names = wp_list_pluck( $foods, 'name' ); // $food_names is now $food_names = array( 'Banana', 'Apple' ); $foods = array( array( 'name' => 'Banana', 'color' => 'Yellow', ), array( 'name' => 'Apple', 'color' => 'Red', ) ); $red_foods = wp_list_filter( $foods, array( 'color' => 'Red' ) ); // $red_foods is now $red_foods = array( array( 'name' => 'Apple', 'color' => 'Red', ) );
  • 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