Skip to content
Public Ticket #7705

Random posts for Archive pages and Mega Menu

Conversation thread

Penci Design replied

Staff Reply

Hi,

1/ I add custom code php to pennews/function.php file  to Random posts for Archive pages and Mega Menu: http://prntscr.com/nchdes

function penci_wpsites_query( $query ) {
    if ( $query->is_category() && $query->is_main_query() ) {
        $query->set( 'orderby', 'rand' );
    }
}
add_action( 'pre_get_posts', 'penci_wpsites_query' );

2/ Random posts for  Mega Menu. I add custom code penci-framwork plugin / mega-menu/menu-render.php line  160 http://prntscr.com/nchdmf

$attr = array(
'post_type'           => $post_type,
'posts_per_page'      => $numbers,
'ignore_sticky_posts' => 1,
'orderby'             => 'rand',
  'post_status'         => 'publish',
'tax_query'           => array(
array(
'taxonomy' => $tax,
'field'    => 'id',
'terms'    => $cat_id,
),
),
);

Note important: please backup the code before update PenNews theme with latest version.

Please check it again,

Best Regards,

PenciDesign

Penci Design replied

Staff Reply

Hi,

Please  send me your website managment information ( admin url site, username and password ) . I will change it help you.

Best Regards,

PenciDesign

free20art started the conversation

Conversation Start

Hello,

I need to have the Category Archive pages and Mega Menus show random ordered posts each time someone goes to a page instead of the newest post first. How can I do this?

Thank you!

Want to join this conversation or access attachments? Sign in first.