try putting your script in a function and running it during an action hook. perhaps the wp_footer hook.
Related Posts:
- Create posts on user registration
- Create posts without login from frontend
- Posts added with wp_insert_post are moved to trash automatically
- Prevent duplicate posts in wp_insert_post using custom fields
- How to avoid duplicate posts on front page?
- duplicate posts when trying to update a post using the wp_insert_post.
- Create new WordPress post [wp_insert_post] based on results of a WP_Query
- Custom Post Type & Author not associating, user post count is 0, api doesn’t return author in post objects
- generate unique slug while inserting post
- wp_insert_post works, but the post isn’t visible in the admin post list or front end
- Email Post Attachment on wp_insert_post Action
- post_content sanitization / transformation process
- wp_insert_post – duration
- How to copy posts from one site to another in real time (not multisite)
- Creating a post from data returned from HTML form
- Multi row post list
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- post category in wp_insert_post
- When creating a post how do you select the format?
- How can I post exact same post but with a few things changed? (with some sort of Automation)
- Adding post date will not insert new post
- wp_insert_post not working fine
- Insert data from custom created PHP page into wp_postmeta table
- How to let a user create a post by submitting a POST form?
- Automatic duplicate/copy of post to a related page in WordPress
- wp_insert_post() Add and specific ID to the body of that
- Random post_id at wp_insert_post
- how to create a category with wp_insert_post and post_category
- Create posts by any logged in users
- wp_insert_post not inserting post
- Creating a frontend blog post form for logged in users only
- Remove duplicated posts in the loop if post has more than one category
- Loop through posts by each term and exclude duplicate posts assigned to several terms
- Insert new post for each user infinite loop error
- How to save the same post in multiple blogs?
- Is there any point to using wp_unique_post_slug?
- Admin notice on wp_insert_post
- simply loop through posts
- Difference between an archive and a page listing posts
- WordPress Queue like Tumblr?
- Update all posts automatically when using post_meta
- Moving WordPress to new server: no posts found
- Post ids are incrementing by an unknown number?
- Get current users post URL?
- Redirect based on user post count
- Remove some articles from the list in WPAdmin for a user
- Pagination – Posting First Page Content
- How to Add ‘Post Categories’ to the Dashboard Sidebar
- How to show featured image in custom post type dashboard post page
- Show total author’s post views by posts post_meta
- Why is my Blog Page ID == First Post ID?
- Featured Image uploaded, attached and set but only appearing in the media library
- WordPress programatically inserted post not showing in authors profile
- Update all comments time to random dates?
- How can I get global $post to work for CPT and update user?
- Unable to restore from backup – how to obtain old blog posts?
- Show only one page link in content pagination
- Include sticky posts on the static page front page
- How can I setup a relationship using categories in WordPress?
- hiding permalink in admin if the user is subscriber
- Exclude current custom post on single post
- How to make default “Privacy Policy Page” a normal page?
- Changing default WP-Site creation date
- Very complex post query
- Delete post revisions only for a single post
- Echo Text If User Is Logged in But NOT the Author of post
- wp_set_object_terms NOT working on CPT, but wp_set_post_terms does
- Update post meta within save_post action
- Where to insert the other site image url for our wordpress post
- Get Users Post ID
- add_rewrite_rule and template redirect not working
- Automate post update for all posts?
- Allowing Users to Register Themselves and Post : Does WordPerss Handle these Problems?
- ACF date picker to trigger category change
- DEL media from the post but keep my featured image or post
- Set post title font size automatically according to number of words in post title
- How can I use query_posts to loop through posts and construct my own content?
- Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
- How to make an image appear as a thumbnail in the blog post?
- How can i take all ids from untrash_post action?
- Can I Paginate Post after every 25 tag?
- How to show posts ordered by random [duplicate]
- Not display post meta if empty
- Query posts from newest category
- Trim excerpt to first paragraph
- post_name is not stored until post is published… where should I store my slug until it goes live then?
- Adding div to WordPress page content
- WordPress loop uses unmodified posts array, why?
- Create new post on user registration
- How to organise post by category and date
- Show post if in category
- How to display custom content in post with category XXX
- Display only posts with comments
- retrieve post slug by post_tags taxonomy
- Hide the contents for specific post
- how to show all type of author posts in author page (SOLVED)
- WordPress Page Column Problem [closed]
- If meta_key exists then don’t select this post?
- Exclude posts by date – related post
- Post pages are redirecting to the 404 page in wordpress