Skip to main content
6 events
when toggle format what by license comment
Sep 16, 2021 at 8:48 comment added Jos Or, maybe better, you could cook up a native SQL query to get the highest numero. Here's an example that might work: SELECT m.meta_value FROM wp_posts p LEFT JOIN wp_postmeta m ON m.post_id = p.ID WHERE p.post_type = 'sep_doc' AND m.meta_key = 'numero' GROUP BY p.ID ORDER BY (m.meta_value * 1) DESC LIMIT 1 Mind you: this will bypass all optimizations Wordpress does on database traffic. You might want to store / cache that value until the sep_doc list is updated and than recache that.
Sep 16, 2021 at 8:48 comment added Jos Sounds like the pre_get_posts action will change the sorting and thus you won't necessarily get the highest numero anymore. So in get_last_numero you should disable that filter / action right before the query.
Sep 15, 2021 at 7:38 comment added Joy So this was working fine, until I decided to rearrange the posts by meta_field_date order by modifying pre_get_posts . Now if date is ordered, its messing the numero. What will be the best way to find the last / highest of the numero field? I am using different code snippets.
Jul 17, 2021 at 16:32 comment added Joy Yes, I changed the function with 'meta_key' => 'numero', 'orderby' => 'meta_value_num', 'order' => 'DESC' and added the (int) as well. It didn't work though. But finally used javascript to put that value in the input field and made that field readonly.
May 13, 2021 at 16:52 comment added Tony Djukic The string + integer conflict is one I kept hitting over and over until it just became routine, I suspect Jos Faber is 100% spot on here.
May 13, 2021 at 13:42 history answered Jos CC BY-SA 4.0