Multiple orderby parameters in pre_get_posts() action

Never forget that there’re actually two filters // Add additional query args that are allowed by the API by default pre_get_posts // Modify the query herself posts_clauses // Inspect the resulting string – test this one in for e.g. phpMyAdmin posts_request So everything you can achieve using the pre_get_posts filter should be done there. The … Read more

How do I get a meta value from WP_Query?

I’ve found a solution to my problem myself. Since none of the already existing answers solved the problem, I figured I could best post mine here to help people with similar problems. The solution: if($res->have_posts()) { $id = $mail_res->posts[0]->ID; // blindly assuming there is only 1 post having baz = baz_value $true_baz = get_post_meta($id, ‘baz’)[0]; … Read more

WP Cron and wp_insert_post

For those who stumble upon this later, use either option 1 or 2 found here: https://core.trac.wordpress.org/ticket/19373. “For other developers who run into this and need to work around it, either of these 2 options work: call wp_set_post_terms() to add your taxonomies after calling wp_insert_post() set up a “current user” in your script before calling wp_insert_post()”

Use WP_Query object inside a function

This is basic PHP. Just a note before I continue, never ever globalize variables. WordPress has already done quite a crappy job regarding this. Globalization is evil, because anyone and anything, knowingly or unknowingly can change a global variable. This makes globals a nightmare to debug. So in short, NEVER EVER globalize. Whenever you need … Read more