• Resolved june01

    (@june01)


    I am using this shortcode to display my posts, but it does not display sticky posts at the top. I couldn’t find anything related to it in the documentation or anywhere :

    [pods name="post" limit="20" template="tem2" orderby="post_date desc"]
Viewing 1 replies (of 1 total)
  • Plugin Support Paul Clark

    (@pdclark)

    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"]
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.