First, I would use WP_Query
instead of the manual DB query (and don’t tell me that’s because of performance because you’re querying 2 times the same thing). Second, you’re saving your post as draft
status and querying post with status publish
Related Posts:
- Remove option to allow trackbacks/pingbacks from post page options
- Display posts by month
- How to get 2 or multiple custom post types in wordpress functions.php
- Creating bulk posts with Youtube videos
- Hide wordpress field if data is empty in post!
- Custom posts in different columns style
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Only display notification on single post
- Auto create description in post
- Add multiple HTML attributes to an Elementor button
- Add a wp editor to custom plugin and save data
- Handling error states with admin_post
- How to Use the Function is_user_logged_in To Display Different Menus?
- WordPress Customizer: How can you have multiple active callbacks on one control?
- Add value to usermeta without removing previous values?
- get_the_content if it contains multiple lines it results in SyntaxError
- String replace WordPress Site Title
- WP_Query with the “offset” argument
- Make custom field meta not display if there is not data in it
- Add attribute / custom attribute to product in woocommerce
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- Get_the_author doesn’t return author name
- PHP can I add line numbers to file_get_contents()
- Displaying theme options in css
- Remove one value in dismissed_wp_pointers?
- Trying to add attribute to my posts’ featured image
- Accessing data from a non-WP database/table within a page content
- How to show part of the_content?
- Selectbox in admin panel function linking to CSS
- Add New User, extra fields which are required?
- Customizer: active_callback and sanitize_callback incompatibility?
- Redirect specific user role to specific site after login?
- Send multiple attachments with wp_mail in PHP
- custom url rewrite for wordpress
- Post + form + action + results on the same page
- Make a list of sites for each user in WPMU – switch_to_blog (display in SITE_ID: 1)
- Menu jumping when calling it via PHP
- Output Video Download Link in template
- Post repeating with infinite scroll
- “operation successful” message
- Count posts on multisite with blog id
- Making (and edit existing) posts with ID included
- Parsing Menu Items and Blog Posts
- Pagination on Custom Post
- $wpdb returns duplicate posts
- How to show an entire post content and not also the excerpt?
- Create page template via functions.php?
- Increment paged on WP_Query
- Delete or edit postmeta with specific meta_key?
- Modify main query before it run without pre_get_post
- .html end of URl affected to SEO?
- Need help removing […] after excerpt
- is_user_logged_in returning nothing on custom page
- Customize field names in backend profile edit page through function.php [duplicate]
- how to add datas in taxonomy to post with wp_insert_post
- Pagination in single.php
- Change permalink structure specific category
- Array data not saving to specified sections. How to make seting independantly?
- I need to display posts in subcategory beside posts in main category
- Integrate otp in my custom singup form
- How to block specific user id in custom login form?
- How to get post image caption by index
- Is there anyway I can call the year once?
- Add a new view on the Woocommerce account page
- Check $post->ID against multiple values
- Posts missing on author page
- How do I add a predefined class to a custom html element?
- How to allow users to save list of posts in wordpress?
- WordPress recent post
- Need to show 7 posts from actual date
- How to separate the taxonomies list from the form so that editing taxonmies is the same as pages and posts?
- How to center all text body in single.php at once?
- Redirect user role to a specific page on login in a multisite network?
- Add custom attribute to product’s HTML to woocommerce cart page
- Remove node from multisites?
- Get the total Author Favorited posts
- custom field – changing an element or background of id div – different versions not working
- Get current_post in reverse order with pagination
- How to get php file based on URL in WordPress
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Replace Underscore (_) on Space ( )
- Basic PHP question (displaying post title over thumbnail) [closed]
- Why isn’t my custom Javascript showing up in my custom template?
- Post from front end form to post_meta
- media_handle_sideload() returned post_id being incremented
- Saving Post redirects to 404 page when php $_GET variable in post body
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- How can I add WordPress Audio Player as featured audio in Audio Blog Posts?
- Where can I find the code for the menu page meta boxes?
- How can i retrive the movies, trailers, news in a single page using search
- wp_head makes my custom page template not work in Customizer?
- link to page_for_posts
- How to customize posts in WordPress by using HTML and CSS?
- foreach all the post
- Woocommerce linking variations
- $post->ID calls for current page, but what is the code to call for any new page created and published in WordPress?
- Blog Posts not sorted and pagination not adjusted after filtering some category
- How to continuously developing a WP site that is already deployed in production without damaging it during development
- WooCommerce: write featured image dimensions to custom fields in product’
- transition_post_status hook, works – but not if the post is new