Your query isn’t giving you a post ID, it’s giving you an entire post. The SELECT *
returns all columns, ID
, post_status
, etc. So setting $my_post['ID'] = $a
doesn’t do anything for you in this case.
Try using: $my_post['id'] = $a->ID;
instead. That should accurately set your ID before you call wp_update_post()
and you should be in business.
Aside from that, I see no problems with what you’re doing … except that querying the database every time the site is loaded might eventually create performance issues. I’d set up an hourly chron job instead to automate the process … then it doesn’t depend on or slow down user traffic.
Related Posts:
- Custom post type for ‘staff’ versus using wordpress user profiles?
- What are the differences between custom post type and custom page templates?
- How to get custom post type label and singular label from its slug?
- next_post_link() not working for single custom post type post
- How to set a default format for a custom post type?
- Now can I group custom post types together?
- Does anyone have any frameworks to setup custom post types and related actions/filters?
- Exclude add_filter from the admin
- Sanitizing post content for use in an email
- Query multiple taxonomy in Custom Post Type
- automatically create taxonomy with same name as post title
- saving custom post type data to different table in wordpress
- Create Custom Post Type Archive Page with Sub Categories Navigation Sidebar
- register_post_type – rewrite / feeds, what’s it for?
- WordPress import not importing custom taxonomy
- Why are navigation items saved in the database?
- Filter posts with meta_query NOT IN where value has multiple values
- Sort admin area by custom Event Date field
- How to change the admin menu “Pages” to something else
- Function error – Use of undefined constant ‘pre_get_posts’ – assumed ‘‘pre_get_posts’’
- add_rewrite_rule and how to get the custom post into the worpress loop the correct way
- What is the use of a custom taxonomy?
- Return array of categories to php function for current post
- Exclude child pages from archive.php
- Placeholder in HTML editor text area?
- Displaying media for custom post type
- Post Submission from frontend with custom field isn’t working
- Insert and then update post_type by wp_update_post
- wp_query check if integer exists in custom field’s array
- Visual editor issue by having multiple tiny mce editors in a CPT
- orderby rand is not working for a custom post types
- custom home page and custom index page?
- Adding Post id to the end of slug in a Custom Post Type
- list taxonomies from a custom post type
- Custom post registration causing errors
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- How to clone Media custom post type?
- cpt and page sharing same base permalink
- Set up post page like JAMA articles
- Import data from CSV with custom taxomony empty
- Allow users to create posts without logging in?
- Custom post type submenu capabilities – custom plugin
- Template for all categories of a custom post type?
- Include related custom fields from one post type in another post type’s JSON feed
- Is there a way to establish parent/child relationship in WP menu links exclusively?
- Importing Data from a Non-WordPress database, into WP
- Add ‘last’ class to second post in featured post loop
- in_category for custom post types
- sort post types by amount of views
- Listing all slugs?
- I can no longer post or even save a draft, getting the error “A post type mismatch has been detected.”
- WordPress hook after post content and meta update
- My custom taxonomy is only displaying 1 of 3 terms
- Custom Field not saving in WordPress
- List categories, subcategories and posts from custom taxonomy and custom post type
- displaying content of custom post type
- How to list top 5 custom post types depending on comments?
- filter the_content, custom post type, and wp_query
- Best way for a plugin to define a custom post type archive template?
- Creating an Events Feed with Sub Pages/Posts for Each Event
- How to make an API call to a custom post type but filtering by meta value?
- Problem with custom loop navigation inside the blog page
- Sudden 404 pages on product category archives
- Display Custom Field or Custom Taxonomy in front page /post/product
- Custom post type defaults to index.php for archive page
- customize Dokan multi vendor: how can i set every Dokan as child of another dokan?
- Why do my custom post types stop displaying over time?
- Simple way to hide\show an announcement (just a div) on homepage?
- Create Custom page with custom domain
- WP_Query for custom taxonomies showing posts from non-specified terms?
- Persist meta box choices throughout all posts of same post type
- How can we display full post on home page rather than excerpt
- Rewrite of Custom Post Type doesn’t work with dynamic data
- Make pagination work as a carousel (custom query)
- Working with Custom Post Type
- Question on templates
- Custom taxanomy and custom post type – pagination leads to 404
- How can I load Template file from wordpress plugin
- Getting all custom post taxonomies and exhibiting only part of them
- Author archive custom posts only?
- update a posts of other custom post type
- Custome post type “tags” pick default archive instead of custom post type archive
- How to return custom posts in loop?
- Custom post type AND custom taxonomy are not connected
- How to delete comma from the end of results? [closed]
- How do I get a nested query to only display content that the main query outputed
- Single page archive – get coresponding taxonomy and terms
- Custom WordPress URL
- Get post id of permalink for a specific custom post type?
- Displaying custom post types with taxonomy
- Add taxonomy to custom post type archive
- Custom taxonomy archive not showing posts of certain child taxonomies
- How to show animal lineage/pedigree in WordPress?
- WP_Query arguments: Loop through custom post type – get all entries except excluded meta_key?
- Custom Post Type Loop breaking php
- Order custom post type is beign ignored
- How do i get the taxonomy term name on the CPT archive page?
- Add a background image into a post [closed]
- Why custom search engine only searches in post titles of custom posts?
- Send email on creation of custom post type and use get_post_meta()