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
- Get WordPress post content by post id
- Get page ID of page that is set as the posts page
- Get Posts Under Custom Taxonomy
- How to limit the number of posts that WP_Query gets?
- Stop WordPress Wrapping Images In A “P” Tag
- When is the ‘post_content_filtered’ column in database cleared by WordPress?
- Turn a URL into an Attachment / Post ID
- GET the excerpt by ID
- Stop WordPress automatically adding tags to post content
- How to update custom fields using the wp_insert_post() function?
- Determine if page is the Posts Page
- How to get ‘post_content’ without stripping tags?
- How to add an admin notice upon post save/update
- Print Current Post Index number within Loop
- Should we trust the post globals?
- Optimize post insert and delete for bulk operations?
- Get the Current Page Number
- How do you add thumbnail support for custom post types?
- How to mark every 3rd post
- Change Posts per page count
- Keep featured content post in homepage with original order
- How to display related posts from same category?
- Can posts have parents?
- Is there a action hook for the “Empty Trash” button?
- How to end the excerpt with a sentence rather than a word?
- How do I check if I linked to a post before I delete it?
- How to change the case of all post titles to “Title Case”
- Appending content with broken in 4.4
- How to get posts published between a date and today?
- ZIP up all images displayed in a [gallery] and offer as download link
- How to detect single.php (but not single-portfolio.php)?
- How to check if post meta key exists or not in wordpress database
- How to remove a column from the Posts page
- removing inline styles from wp-caption div
- What is the use of to_ping and pinged column?
- How to use “Add link” pop up for a WordPress widget
- Remove Categories / Tags From Admin Menu
- How to retrieve text only from wp_content() not from wp_excerpt()?
- Stop WP from creating “Sample Page” and “Hello World!” post
- Where is the old post permalink slug stored?
- How to Create Editable Blocks of Text for the Homepage?
- Keyboard shortcut for updating a page or post?
- Add custom Attachment Display Setting for images
- Rewriting post slug before post save
- Apply the_title() filter in post & page title, but not in menu title
- How to Change Order of Posts in Admin?
- is it possible to get next_post_link
- Get post content by ID
- How to get post creation date?
- Update post counts (published, draft, unattached) in admin interface
- Function to execute when a post is moved to trash .
- How to get post ID of the current page/post inside a widget?
- add action only on post publish – not update
- How to display by default only published posts/pages in the admin area?
- How do you add Read more … link to posts?
- How to make comments work for a post loaded per Ajax?
- Is there an if statement that can determine if a post in the loop is the last post?
- Get current menu_order
- How to show related posts by category
- Changing the post date and time with function
- simply loop through posts
- Difference between an archive and a page listing posts
- Delete Associated Media Upon Page Deletion