Automattic / Automattic/WP-Job-Manager

Use $query_args When Determining Random Ordering

Open
#1,558 1 comment 0 reactions 0 assignees View on GitHub
[Status] Accepted Enhancement
Dominant language
PHP
Stars
899
Forks
369
Avg merge
11h 37m
Merged PRs (30d)
12

Description

#### Steps to Reproduce
1. Use the Listify theme.
2. Sort listings by Random.

#### What I Expected

Listings to `shuffle` on each load.

#### What Happened Instead

They appear in the same order.

#### Context / Source

When random ordering was optimized/fixed it switched from looking at `$query_args` to `$args` for the status of `orderby`.

`$args` has no filter so there no way to intercept a previously non-random query and make it random.

https://github.com/Automattic/WP-Job-Manager/blob/master/wp-job-manager-functions.php#L198

I think https://github.com/Automattic/WP-Job-Manager/blob/master/wp-job-manager-functions.php#L198 should check for `$query_args['orderby']` and in https://github.com/Automattic/WP-Job-Manager/blob/master/wp-job-manager-functions.php#L125 set a flag that it is `rand_featured`.

```
if ( $rand_featured ) {
usort( $result->posts, '_wpjm_shuffle_featured_post_results_helper' );
} elseif ( 'rand' === $query_args['orderby'] ) {
shuffle( $result->posts );
}
```

Contributor guide

Open the contributing guide

Research direction

Read wp-job-manager-functions.php around lines 125 and 198, comparing how $query_args and $args determine ordering. Reproduce random ordering with the Listify theme, then verify that listings shuffle on each load and that the existing featured-random behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.