Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created April 4, 2022 16:39
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 wpexplorer/70c06d014e455256e100e0b209056821 to your computer and use it in GitHub Desktop.
Save wpexplorer/70c06d014e455256e100e0b209056821 to your computer and use it in GitHub Desktop.
Custom Query Callback Function with Shortcode Attributes | Total WP Theme
function your_function_name( $shortcode_attributes = array() ) {
$query_args = array(
'post_type' => 'staff',
);
// Get shortcode unique ID.
$unique_id = $shortcode_attributes['unique_id'] ?? '';
// Add custom query arguments based on the unique ID.
switch ( $unique_id ) {
case 'unique-id-1':
$query_args['posts_per_page'] = '2';
break;
case 'unique-id-2':
$query_args['posts_per_page'] = '2';
break;
default:
$query_args['posts_per_page'] = '3';
break;
}
return $query_args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment