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
- How to update custom fields using the wp_insert_post() function?
- Why have on every line
- Function to return true if current page has child pages
- Disable Attachment Pages Completely
- WordPress and event-driven programming – what is it about?
- Cleaning up WordPress to improve performance?
- Include a external PHP file into a WordPress Custom Template
- List of all theme customizer control types?
- Inject post (from specific category) between posts in Loop
- Show the most popular post per week
- Add a class to links in the visual editor (how to get old dialog back)
- Get author full name
- Receiving Stripe Webhooks on a wordpress website
- How to remove hardcoded characters from playlists?
- Creating custom Woocommerce attribute taxonomies from a plugin
- Integrating WordPress to my website, while keeping my own authentication system
- Remove/unset options field from backend Settings->General?
- Custom SQL query to get List of posts with featured image url
- How to preserve PHP modifications while upgrading WordPress?
- What would be a PHP command to erase all posts from category X from the last month?
- Add a wp editor to custom plugin and save data
- Alter query on edit.php
- Permanently remove first image from posts
- Admin Bar (Toolbar) not showing on custom PHP file that loads WordPress
- Display a selected custom product option in WooCommerce cart
- Removing jQuery migrate and working with dependencies
- Load post content into iframe
- is there a simple way to list every templates / php files used to generate a specific page?
- wp_customize_image_control default value
- Custom post type column which compares dates?
- How to get year, month and hour in WordPress?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- Walker class: Problems with understanding how walk() method can be called without error
- Handling error states with admin_post
- How to Use the Function is_user_logged_in To Display Different Menus?
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- Change comments form title on a page by page basis
- Limit the Excerpt field in WP-Admin in words
- How to create different menu’s for not logged in visitors and for logged in members?
- Search and Replace in database: How to replace data in SQL dump file on Windows?
- 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
- Edit postmeta when user changes user role?
- Looking to exclude blog posts from category Previous/Next buttons
- Setting up the child theme so as to enable right-to-left WordPress?
- Custom Loop Pagination on WordPress
- Insert code when users come from an specific referer
- Authenticating to WordPress, using my own authentication two-factor system
- delete an array element when its date expires
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- Handling an Ajax form submit
- Automatic Excerpt Not Working
- How to display related posts from parent category
- How to add default images into theme customizer image control?
- String replace WordPress Site Title
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Is it recommended to pass some data to scripts in `wp_enqueue_scripts`?
- Using a javascript file to access a get posts array
- WP_Query with the “offset” argument
- Go to / Scroll to Password Field on WordPress Posts After Submit With Message(s)
- Overriding a theme redux file in child theme
- WordPress Ajax Data problem
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Remove all nav menu classes ( but keep useful ones… )
- Widgets not showing in my custom theme
- New Plugin Review
- Make custom field meta not display if there is not data in it
- Type hinting and void return question
- Print number of post (in reverse)
- Use template for posts with a particular category grandparent
- Count number of published posts by type
- How to display custom field on homepage
- Customized title tag for each page in pagination?
- WP Insert Post function – Insert Post Thumbnail
- Add attribute / custom attribute to product in woocommerce
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Automatically generate Post/Page from searched Database item?
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- How is WordPress manipulating the posts like there are folders?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- Get_the_author doesn’t return author name
- Styling images coming from another blog
- How to break down importing of feeds
- Wrap First Character after in a tag
- Get taxonomy terms only of the WP_Query current posts
- Exclude posts from homepage having a specified tag
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- How do I implement a .diff changeset from core.trac.wordpress.org locally?
- PHP can I add line numbers to file_get_contents()