[wp-trac] [WordPress Trac] #34766: Order by rand in taxonomy page don't work
WordPress Trac
noreply at wordpress.org
Sun Nov 22 18:26:25 UTC 2015
#34766: Order by rand in taxonomy page don't work
------------------------------+-----------------------------
Reporter: sebastian.pisula | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
------------------------------+-----------------------------
I use filter:
{{{#!php
<?php
add_action( 'pre_get_posts', 'hook' );
function hook( $query )
{
/** @var WP_Query $query */
if ( $query->is_main_query() && $query->is_tax( 'landing-page-
highlight', 'special-offer' ) ) {
$query->set( 'posts_per_page', -1 );
$query->set( 'orderby ', 'rand' );
}
}
}}}
Query Monitor show that order is random. If I use WP_Query in taxonomy.php
template then this work:
{{{#!php
<?php
global $wp_query;
$term = $wp_query->queried_object;
$args = array(
'orderby' => 'rand',
'posts_per_page' => - 1,
'post_type' => 'landing-page',
'tax_query' => array(
array(
'taxonomy' =>
$term->taxonomy,
'field' => 'slug',
'terms' => $term->slug,
)
)
);
$wp_query = new WP_Query( $args );
?>
}}}
And My register taxonomy:
{{{#!php
<?php
register_taxonomy( 'landing-page-highlight', array( 'landing-page' ),
array(
'labels' => array(),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'rewrite' => array(
'slug' => 'product',
'with_front' => true,
'hierarchical' => true,
),
) );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34766>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list