Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/9425101 to your computer and use it in GitHub Desktop.
Save Shelob9/9425101 to your computer and use it in GitHub Desktop.
<?php
/**
* Change default experation time per use
*/
$expire = DAY_IN_SECONDS;
$args = array( 'post_type => 'page', 'posts_per_page' => 3 );
if ( function_exists( 'jpd2_better_query' ) {
$name = foo;
$foo_query = jpd2_better_query( $args, $name );
}
else {
$foo_query = new WP_Query( $args );
}
/**
* Using the 'JPD2_expire' action
*/
add_action( 'JPD2_expire', 'slug_jpd2_exp_cb' );
function slug_jpd2_exp_cb() {
$expire = WEEK_IN_SECONDS;
return $expire;
}
/**
* Using JPD2_EXP constant
* Set before plugin is loaded, ie wp-config.php
*/
if ( !defined( 'JPD2_EXP' ) {
define( 'JPD2_EXP', DAY_IN_SECONDS );
}
?>
<?php
/**
* Basic Use
*/
$args = array( 'post_type => 'page', 'posts_per_page' => 3 );
$name = foo;
$foo_query = jpd2_better_query( $args, $name );
/**
* Safest Usage
*/
//WP_Query Example
$args = array( 'post_type => 'page', 'posts_per_page' => 3 );
if ( function_exists( 'jpd2_better_query' ) {
$name = foo;
$foo_query = jpd2_better_query( $args, $name );
}
else {
$foo_query = new WP_Query( $args );
}
//WP_User_Query
$args = array(
'search' => 'Josh',
'search_columns' => array( 'user_login', 'user_email' ),
);
if ( function_exists( 'jpd2_better_query' ) {
$name = foo;
$foo_query = jpd2_better_query( $args, $type='WP_User_Query', $name );
}
else {
$foo_query = new WP_User_Query( $args );
}
//WP_Meta_Query
$args = array(
'relation' => 'OR',
array(
'key' => 'lightsbar_color',
'value' => 'red',
'compare' => '='
)
);
if ( function_exists( 'jpd2_better_query' ) {
$name = foo;
$foo_query = jpd2_better_query( $args, $type='WP_Meta_Query', $name );
}
else {
$foo_query = new WP_User_Query( $args );
}
?>
<?php
//when using with Pods class, $args is passed to pods::find Params see http://pods.io/docs/code/pods/find/
//$pod is the name of the Pod being queried.
//get 5 items in 'flightless_birds' pod
$args = array( 'limit' => 5 );
$pod = 'flightless_birds';
$pods = jpd2_better_query( $args, $type='pods', $name='5-birds', $pod );
if ( $pods != FALSE ) {
while ( $pods->fetch() ) {
echo $pods->field( 'species_name' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment