[Support request] Questions about query loop

Home Forums Support [Support request] Questions about query loop

Home Forums Support Questions about query loop

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2358596
    Kees

    Hi,

    I have to questions. We have blogs and we show them on the homepage with a query loop.

    1. Is it possible to show the post on the homepage with a queryloop in a random order in WordPress?
    2. Is it possible to show the post ont the homepage with a queryloop in order of most read.

    Would help a lot. Please let me know.

    Regards,
    Kees

    #2358725
    Fernando
    Customer Support

    Hi Kees,

    Yes, it should be possible to add a GB Query Loop Block that’s ordered randomly. Since your homepage is a static page, you can add it directly to the page. You’ll need a code like this:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-class-name' ) !== false ) {
    		$query_args['orderby'] = 'rand';
           }
    	   return $query_args;
        }
    
        return $query_args;
    }, 10, 2 );

    Add my-class-name to the class list of the Grid Block in the Query Loop Block.

    2. It should also be possible but this is more complicated. You would need a plugin that records post views, and then use the post meta for the views generated by that plugin in a custom code.

    Lastly, for GenerateBlocks related inquiries, please reach out to us here: https://community.generateblocks.com/

    #2358750
    Kees

    Hi,

    Thanks! Helped a lot!

    #2358751
    Kees

    There was an error in your code btw. But fixed it.

    #2360922
    Fernando
    Customer Support

    I see. You’re welcome Kees!

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.