-
Notifications
You must be signed in to change notification settings - Fork 368
[jobs] shortcode: add author attribute to filter listings by user ID #2935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 6 commits
62c0803
ea7d6e1
e71145e
ed1e3b6
748597e
d6784d5
d0c636d
d50a788
336c898
6159ea7
d4b32ce
97d8e59
9a2fe36
e469f51
d7d1bc3
1872f2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,6 +192,15 @@ function get_job_listings( $args = [] ) { | |
| ]; | ||
| } | ||
|
|
||
| if ( ! empty( $args['author'] ) ) { | ||
| $author_ids = is_array( $args['author'] ) | ||
| ? array_filter( array_map( 'absint', $args['author'] ) ) | ||
| : array_filter( array_map( 'absint', explode( ',', $args['author'] ) ) ); | ||
| if ( ! empty( $author_ids ) ) { | ||
| $query_args['author__in'] = $author_ids; | ||
| } | ||
| } | ||
|
|
||
| $job_manager_keyword = sanitize_text_field( $args['search_keywords'] ); | ||
|
|
||
| if ( ! empty( $job_manager_keyword ) && strlen( $job_manager_keyword ) >= apply_filters( 'job_manager_get_listings_keyword_length_threshold', 2 ) ) { | ||
|
|
@@ -219,6 +228,11 @@ function get_job_listings( $args = [] ) { | |
|
|
||
| $should_cache = 'rand_featured' !== $args['orderby'] && 'rand' !== $args['orderby']; | ||
|
|
||
| // Bypass cache when author filter is active to avoid stale results. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure this is required? The cache key is derived from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had issues while applying the PR that the change didnt show. but when i retest now all seems fine even without this part. so i went ahead and removed it now @donnchawp - thanks! |
||
| if ( ! empty( $query_args['author__in'] ) ) { | ||
| $should_cache = false; | ||
| } | ||
|
|
||
| // Cache results. | ||
| if ( apply_filters( 'get_job_listings_cache_results', $should_cache ) ) { | ||
| $to_hash = wp_json_encode( $query_args ); | ||
|
|
@@ -630,6 +644,7 @@ function job_manager_get_filtered_links( $args = [] ) { | |
| 'search_location' => $args['search_location'], | ||
| 'job_categories' => implode( ',', $job_categories ), | ||
| 'search_keywords' => $args['search_keywords'], | ||
| 'author' => ! empty( $args['author'] ) ? $args['author'] : '', | ||
| ] | ||
| ) | ||
| ), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.