Replace this line:
if ($old_status != 'draft' || $new_status != 'publish') {
with:
if ( $post->post_type != 'post' || $new_status != 'publish' || $old_status != 'auto-draft' ) {
You want to run your code on post
transition from auto-draft
to publish
, which will occur once only, when your post
is created.
UPDATE
The problem is in this part of your code:
$resp = curl_exec($curl);
error_log(" [ ". date("Y-m-d H:i:s") . " ] sending post with ID = ". $post_ID ."\n", 3, $_SERVER['DOCUMENT_ROOT'] . "/log.txt");
if (!curl_exec($curl)) {
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
You are calling curl_exec($curl)
in two lines! First:
$resp = curl_exec($curl);
and second:
if (!curl_exec($curl)) {
Change your if
statement to:
if (!$resp) {
Related Posts:
- transition_post_status hook, works – but not if the post is new
- Change the footer text on the login page
- How to remove a metabox from menu editor page?
- Check if page parent has certain template
- Hooking new functions to actions + passing parameters
- Is $hook a global variable in WordPress
- Insert all post IDs in new database table
- Randomise upload filenames (or another solution to hide the original image URL from theft?)
- Handling Body class based on Template
- Automatically remove a canceled order in Woocommerce
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- WordPress Gravatar filter is removing my custom attributes
- Error in custom php function doesn’t exist
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- Return a numerical function value in Customizer controls
- Modify custom field input data before creating a new post
- how to make custom ajax handler?
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- Run a code only on theme activation only during first activation
- Theme not calling Jquery properly
- WordPress redirect redirecting too many times or not at all
- Why does the post_type_link hook everything twice?
- How to have different site identity logos on each page on Astra Theme [closed]
- How can I hook into the wp_mail function used by BackWPup?
- Get user custom field value on function.php
- Adding function to child theme’s function.php
- Must filter functions receive all arguments passed to them?
- Creating customized php files in theme folder
- Dynamically Generate Functions and Hooks
- How to pass hook variable to function?
- How do I add a function to parent theme
- Contain multiple page templates in one PHP custom template file in WordPress?
- Wp_Schedule_Event every few minutes doesn’t work
- Adding custom field to product category and show it to shop/category shop page
- Custom meta box is not displaying value showing tag as empty
- Discount in the specific product title using keyword ( Woocoommerce )
- How do I get the value of a current user’s custom field?
- Hook into all password resets in WordPress and get password before hashing?
- Getting page / post URL on publish and / or update
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- WordPress HTML Helper
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- Is there a hook that I can use when a fatal error occurs?
- WordPress and event-driven programming – what is it about?
- How to overwrite youtube embed?
- How to add SVG icon above product tab title
- Generating add_settings_section() calls dynamically
- Remove query string specific key value
- is_page “range” for if statement?
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Converting HTML Template to WordPress Theme
- Error when adding excerpt to the content through functions.php
- Add data attribute to each li in menu
- Prev/Next child navigation for current page modifications?
- Adding rel tag to all external links
- How can I apply_filters from inside a function?
- Populate editor with some content of a page with a page template
- Way to add captions to gallery images by code
- How to make container class in PHP
- How to create an ACF shortcode with Repeater Field in WordPress? [duplicate]
- Prev/Next Links Broken on Static Front Page Pagination
- How do I check or test a WordPress Auto Year Change Script?
- Is there a built-in function to generate multiple paragraph tags based on a string with new line separators?
- How to add no follow to specific links?
- Function for simple math doesn’t work what am I doing wrong? [closed]
- How to hide the author box of a specific user?
- Add date before entry title in Twenty Twelve
- How do i wrap woocomerce attribute in list?
- Removing files programmatically
- WordPress theme showing blank page
- Defining multiple categories for showing latest posts
- The additional fee for the COD payment method not visible in the front-end
- PHP identify duplicate words in a text string against a list of words
- How to access all meta data for RSS feed?
- Why Is Number of views on wordpress single post wrong?
- How to add and subtract user meta values after post meta update
- Multiple AJAX handler functions conflict in functions.php
- add another variable to php function
- How to remove get_header From all single pages in wordpress with functions.php without plugin?
- Change lost password url to a mailto URL in WordPress
- Send POST request to Flask app from functions.php file
- 500 Error, Get custom field and returning it
- How to auto-generate random numbers in username?
- Remove generated category and tag class names from woocommerce product & blog listings markup
- How to add a custom class for iframe by embed_oembed_html
- Restrict File Type Uploads by User on Wordress via functions.php
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Matching multi user
- AJAX Returning Way Too Many Posts
- Where can I find the declaration of `$_wp_theme_features`?
- redirect 301 with special character like WIX site “#!”
- How I can add div to menu?
- Modify category archive page loop on functions.php
- How to print redirected query string variables to the page?
- Admin-area broken through weird issues
- Check if values exists DB
- How to modify this function to exclude also the post belonging to a specific category?