Skip to content
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

Sorting Loans by return date hides un-returned items #40

Closed
kittsville opened this issue Apr 15, 2015 · 1 comment
Closed

Sorting Loans by return date hides un-returned items #40

kittsville opened this issue Apr 15, 2015 · 1 comment
Assignees
Labels

Comments

@kittsville
Copy link
Owner

Simple enough bug, if you sort the Loans table by their return dates the table only displays items that have been returned. I'm guessing because the SQL query only includes Loans that actually have the return date meta value.

Bug was introduced in d762f82 as part of #35

@kittsville kittsville added the bug label Apr 15, 2015
@kittsville kittsville self-assigned this Apr 15, 2015
@kittsville
Copy link
Owner Author

Further inspection confirms this is the case as the table is the sorted result on the intersection of the post table and rows of the post meta table for the return date. No return date == not in the intersection.

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
INNER JOIN wp_postmeta
ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE 1=1
AND wp_posts.post_type = 'wp_lib_loans'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'future'
OR wp_posts.post_status = 'draft'
OR wp_posts.post_status = 'pending'
OR wp_posts.post_status = 'private')
AND ( wp_postmeta.meta_key = 'wp_lib_return_date' )
GROUP BY wp_posts.ID
ORDER BY wp_postmeta.meta_value+0 ASC
LIMIT 0, 20

The will definitely work but not very DRY solution would be to create a custom SQL query via a post_clauses hook. It'd be more sencible however to first see if there's any way to modify the query sufficiently via small pre_get_posts changes. This might be worth leaving until tomorrow as I've been working for 11 or so hours and SQL is loosing its charm.

kittsville added a commit that referenced this issue Apr 16, 2015
Fixed #40 whereby sorting loans table by items' return dates caused all
un-returned items not to be displayed.
kittsville added a commit that referenced this issue Apr 16, 2015
Added sortable admin tables to development

Closes #35, closes #40, closes #41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant