Query within a foreach within a query (queryception)

Good for you that you’ve corrected the $posts that was undefined, but then: There’s no need to call $the_query->get_posts() because when WP_Query is instantiated with a non-empty query, e.g. new WP_Query( ‘post_type=house’ ) (contains one query arg — post_type) as opposed to new WP_Query() (no query args specified), the get_posts() method in that class will … Read more

How to properly delete custom post type posts programmatically

I believe I found the problem. Since the wp_delete_post was before the redirect, WordPress tried to reload an inexistent page (and comments, since they are deleted automaticaly with the command) and that generated the error. The new code is as such and it’s not generating errors: if( has_post_thumbnail( $post_id ) ) { $imagem_principal_id = get_post_thumbnail_id( … Read more

Get taxonomy singular name instead of taxonomy slug inside $taxonomy query

get_object_taxonomies() by default returns a list of taxonomy names like category and post_tag. If you want the function to return taxonomy objects instead, then set the second parameter to objects: $taxonomies = get_object_taxonomies($custom_post_type_name, ‘objects’); And then change your foreach () code to foreach ($taxonomies as $taxonomy => $tax_object), then use $tax_object->labels->singular_name to access the singular … Read more

Why does wp_update_post causes white screen?

When commenting out wp_update_post( $post ), the update_post_meta is working fine. Yes, the problem is not with update_post_meta(), but it is wp_update_post() because it uses wp_insert_post() which fires the save_post_foglalas hook (i.e. save_post_<post type>), and because your function calls wp_update_post(), then your function gets called infinitely and eventually caused the White Screen Of Death (WSOD). … Read more

Query all post and CPT from 2 specific taxonomies AND by ACF custom field

Finally I found a solution! Here is the query in case someone needs it : // first query $first_ids = get_posts(array( ‘fields’ => ‘ids’, ‘posts_per_page’ => ’10’, ‘post_status’ => ‘publish’, ‘post_type’ => array(‘post’), ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, )); // second query $second_ids = get_posts(array( ‘fields’ => ‘ids’, ‘posts_per_page’ => ’10’, ‘post_status’ => ‘publish’, … Read more