Site icon Hip-Hop Website Design and Development

After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel

Made s script that under certain conditions adds a new custom post to the database. All works fine. But there is a flow. After writing the post to the database with my script I can not extract it with WP_Query. If I add posts directly from the wp-admin panel all wokrs fine. But is I add post with my script I can not extract them with WP_Query. The new added post appears in the posts list in the wp-admin panel with all the needed values, all is cool but not visible to WP_Query. It only becomes visible after I change any of the post’s custom fields in the wp-admin panel and press the Update button. After refereshing the page all starts to work perfectly.

The new post seems to be published and I can even extract specific fields from it when I list all the available posts of this type.

The query. I know for a fact that the query works fine because it works for the posts I ppublish directly from the wp-admin panel.