That such guys would like to send the data of a newly created post to an external php with the action of wordpress, but I do not know how to do it, I have tried with ajax but apparently it is not executed
function enviar_datos( $post_id ) {
$post_title = get_the_title( $post_id );
//enviar variable $post_title a un php en otro servidor
}
add_action('publish_post', 'enviar_datos', 20);
How could I do it? I've already tried with ajax and it does not work
wp_register_script(
'your-script',
get_template_directory_uri() . '/js/ajax_test.js',
array('jquery')
);
function enviar_datos( $post_id ) {
var titulo = $post_title = get_the_title( $post_id );
$params = array (
'varHome' => titulo
);
wp_enqueue_script('your-script');
wp_localize_script('your-script','vars_inline',$params);
}
add_action('publish_post', 'enviar_datos', 1);
AJAX
jQuery(document).ready(function($) {
var datos =vars_inline.varHome;
jQuery.ajax({
type: "POST",
url: 'http://ejemplo.com/pruebas/index.php',
data: { datosz: datos },
success: function( data ) {
console.log(data);
}
});
})
Or if you know of a plugin that triggers an event when a new post is created and sent me the data
Thanks in advance