• Resolved Kai

    (@kaichi)


    Hello,
    Is it possible to show only sticky posts?
    I noticed that there is the option to include/exclude sticky posts, but what if I want to show just sticky posts?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Code Amp

    (@codeamp)

    Hey @kaichi

    I’ll put this as a feature request and hopefully we can get this added.

    If you are comfortable with a little PHP and WP actions + filters, I can point you in the right direction to achieve this (without waiting for our update)?

    Thanks

    Thread Starter Kai

    (@kaichi)

    Hello @codeamp,
    Yes please, if you can help me with PHP and WP actions will be great.

    Thank you!
    Regards,
    Kai

    Plugin Author Code Amp

    (@codeamp)

    Hey @kaichi

    You can use our query_args filter, to modify the query, found here:
    https://customlayouts.com/documentation/action-filter-reference/

    And combine it with the info from this stack exchange post:
    https://stackoverflow.com/a/19814472/459359

    And you should end up with code that looks like:

    function layout_query_args( $query_args ) {
    	// Get sticky posts from DB
    	$sticky_posts = get_option('sticky_posts');
    	
    	if ( ! empty( $sticky_posts ) ) {
    		// Modify the query
    		$query_args['post__in'] = $sticky_posts;
    	}
    	// Always return in WP filters
    	return $query_args;
    }
    
    add_filter( 'custom-layouts/layout/query_args', 'layout_query_args', 10 );

    Note- I didn’t get to test this – but in principal everything looks correct.

    Best

    Thread Starter Kai

    (@kaichi)

    @codeamp Thanks a lot! This is exactly what I need and the script works as intended without any modification.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Sticky posts only’ is closed to new replies.