Sticky post IDs are stored in the wp_options
table. A separate shortcode can be used above to query them by ID.
Adding a sticky posts query to the Pods shortcode with a Code Snippet:
/**
* Allow STICKY to be used in where clause of a Pods Block, Shortcode, or ->find() query.
*/
add_filter(
'pods_pods_find',
function( $params ) {
$params = (array) $params;
if ( array_key_exists( 'where', $params ) ) {
$sticky_posts = (array) get_option( 'sticky_posts' );
$params['where'] = str_replace(
'STICKY',
( empty( $sticky_posts ) )
? 'FALSE'
: sprintf(
't.ID IN( %s )',
implode( ',', $sticky_posts )
),
(string) $params['where']
);
}
return (object) $params;
}
);
- For
where
field on Pods block or shortcode, put STICKY
:
[pods name="post" limit="20" template="tem2" where="STICKY" orderby="CAST( t.post_date AS DATETIME ) desc"]
STICKY
can be combined with any other query, e.g., STICKY AND category.name = 'puppies'
To display sticky above other posts, it would be two shortcodes:
[pods name="post" limit="20" template="tem2" where="STICKY" orderby="CAST( t.post_date AS DATETIME ) desc"]
[pods name="post" limit="20" template="tem2" orderby="CAST( t.post_date AS DATETIME ) desc"]