Plugin Author
Chouby
(@chouby)
Hi!
Are these 50 pages titles so close that you can’t distinguish them?
The other thing that does not help is ‘orderby’ => ‘title’.
Would your problem be solved if I removed this? The idea was to be sure that the searched page title would be in the first results. But I may be wrong.
Is it not better to have a possibly very long list instead of not finding the desired post at all?
In a previous version of Polylang, the list used to be very long and this did not scale at all, creating huge problems for some users having thousands of posts. I agree that 10 posts could be a bit small in some edge cases and I could try to look for a better compromise. What would look reasonible for you?
Did you try to change this with a ‘parse_query’ or ‘pre_get_posts’ filter?
Hi!
Are these 50 pages titles so close that you can’t distinguish them?
Not at all, I can distinguish them.
In a previous version of Polylang, the list used to be very long and this did not scale at all, creating huge problems for some users having thousands of posts. I agree that 10 posts could be a bit small in some edge cases and I could try to look for a better compromise.
I sure do understand.
Would your problem be solved if I removed this? The idea was to be sure that the searched page title would be in the first results. But I may be wrong.
Indeed, by removing 'orderby' => 'title'
it’s better imho.
By doing so, we have something like that in the query:
ORDER BY wp_posts.post_title LIKE '%foobar%' DESC, wp_posts.post_date DESC
But there’s a catch. We have this behavior since WP 3.7 only.
So, for me, I think the best compromise would be to remove orderby
and maybe set numberposts
to something like 20. For WP 3.6.1 and less, a little hack may be needed for the order I guess.
PS: in my framework I use a tweaked version of the “Attach media” modal window. (go to wp-admin/upload.php
, use the old list view, find an unattached media, click “Attach”).
Plugin Author
Chouby
(@chouby)
I believe that I can safely introduce these changes in Polylang 1.7, as I already decided to drop the support of WP versions older than 3.8.
PS: in my framework I use a tweaked version of the “Attach media” modal window. (go to wp-admin/upload.php, use the old list view, find an unattached media, click “Attach”).
What do you mean?
I mean this: https://www.dropbox.com/s/2n5w72rmkeikr0j/media-attach-modal.png?dl=0
But maybe it’s a bit overkill here, and it needs lots of tweaks because it’s not “reusable” by default 🙁
Plugin Author
Chouby
(@chouby)
Yes I understood you were speaking fo this modal but I don’t understand the link to this topic. Note that Polylang 1.7 will filter the list per language.
In both cases we search for a post/page/poney, that’s the link 😉
But once again, using this modal instead of your auto-complete might be overkill imho, so… forget it x)
Plugin Author
Chouby
(@chouby)
I understand now! Sorry to be so slow…
Hi again.
I got a weird behavior today.
I edited the plugin by removing the orderby
argument, waiting for version 1.7.
So, typing the exact post title should return the desired post at the top of the list. But it wasn’t. Even by setting numberpost
to 20 was not enough, I had to set numberpost
to -1 to finally see it appear oO
So, I was thinking, the best thing to do is probably to add a filter to those arguments. This way, people like me could use it to set numberpost
and/or orderby
whatever we like.
What do you think?
(the other way is to create my own ‘wp_ajax_pll_posts_not_translated’ action callback, I’m not a fan :/)
Plugin Author
Chouby
(@chouby)
That should not be a big problem for me to do that.
Wouldn’t ‘pre_get_posts’ be sufficient?
However I wonder why this happens. Except for the tax_query in Polylang and the number of posts, it now should be quite similar to the query done in wp_ajax_find_posts(). Have you the same issue with this function?
Wouldn’t ‘pre_get_posts’ be sufficient?
How do I target this particular query in that case? :/
However I wonder why this happens.
Same here.
Have you the same issue with this function?
I just checked it out and… yes o__O
I typed the exact page title and the desired page was in position 5.
Digging further, I think it’s because more than 1 search word.
Search for “yolo foobar”:
[search_orderby_title] => Array
(
[0] => wptt_posts.post_title LIKE '%yolo%'
[1] => wptt_posts.post_title LIKE '%foobar%'
)
==>
ORDER BY (CASE WHEN wp_posts.post_title LIKE '%yolo foobar%' THEN 1 WHEN wp_posts.post_title LIKE '%yolo%' AND wp_posts.post_title LIKE '%foobar%' THEN 2 WHEN wp_posts.post_title LIKE '%yolo%' OR wp_posts.post_title LIKE '%foobar%' THEN 3 WHEN wp_posts.post_content LIKE '%yolo foobar%' THEN 4 ELSE 5 END), wp_posts.post_date DESC
If I read this correctly (I’m not a SQL ninja), I think something is missing here (ASC). It should be THEN 4 ELSE 5 END) ASC, wp_posts.post_date DESC
In other words, I think it’s a bug in WordPress.
So, if you’re up for a filter for the args, it would be helpful 🙂
Easier to read:
ORDER BY (
CASE WHEN wp_posts.post_title LIKE '%yolo foobar%' THEN 1
WHEN wp_posts.post_title LIKE '%yolo%' AND wp_posts.post_title LIKE '%foobar%' THEN 2
WHEN wp_posts.post_title LIKE '%yolo%' OR wp_posts.post_title LIKE '%foobar%' THEN 3
WHEN wp_posts.post_content LIKE '%yolo foobar%' THEN 4
ELSE 5 END
),
wp_posts.post_date DESC
Should become:
ELSE 5 END
) ASC,
wp_posts.post_date DESC
OK I give up trying to understand. Even with ASC
I have the exact same thing >_<
Plugin Author
Chouby
(@chouby)
Wouldn’t ‘pre_get_posts’ be sufficient?
How do I target this particular query in that case? :/
By the same way WP knows which ajax function to call
if ('pll_posts_not_translated' === $_REQUEST['action']) {
...
}