-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The WPExpress/Query component is a set of classes which help you run the DB operations in a safe environment.
The Query class is a container for static methods to instantiate every class (Post, MetaField, Taxonomy) related to the DB.
Unlike the classes in WPExpress this method return WordPress specific objects. So if for instance, if you wanted to create a function to return the permalinks of 5 Custom Post Types let's call'em Books, you will do something like this.
function getFiveBooksPermalinks()
{
$list = array();
$fiveBooks = Query::Custom('book')->limit(5)->get();
foreach($fiveBooks as $post)
{
$list[] = get_permalink($post->ID);
}
return $list;
}
Or something a little prettier like this
function getFiveBooksPermalinksImproved()
{
$fiveBooks = Query::Custom('book')->limit(5)->get();
$return array_map( function($post){
return get_permalink($post->ID)
}, $fiveBooks );
}
Notice the use of post->ID. This is a WP_Post object. You can call properties like $post->post_parent, $post->post_title, and so on.
WPExpress/Query uses only WordPress and vanilla PHP objects.
To activate helper methods like getPermalink, getThumbnail and others, you have to use WPExpress/BaseModel
All the documentation for the class is contained in the WPExpress/Wiki. Enjoy!
Made with <3 in Cancún, México by Page Carbajal