Save wordpress post once it was created - wordpress

I have custom wordpress post type (job_listing - from WP Job Manager plugin) and add new posts via REST API requests (Postman). The problem is one meta field (geolocation position) in this post becomes visible on the frontend only when I manually open this newely created post and click on 'Update'/'Publish' button.
I'm thinking of the function that programmatically simulate this action (click on the Update button) but only once (when the custom post type was created).
function update_job_once_created ( ) {
save/update this post;
}
add_action( 'save_post_job_listing', 'update_job_once_created' );

Related

How to ignore required fields in ACF ( Advanced Custom Fields ) plugin for DRAFT status in WordPress

I have ACF ( Advanced Custom Fields ) fields in WordPress website. The form the very lengthy. So it will take time to fill all the details for Admin user.
I need to ignore require validation when the post status is DRAFT or Will be DRAFT.
So that Admin can save data and come back later and fill the data.
The validation needs to be work only when the post status is not DRAFT.
I have tried this function but it is not working properly.
`
add_action('acf/validate_save_post', 'clear_all_errors', 10, 0);
function clear_all_errors() {
acf_reset_validation_errors();
}
`

How to change WooCommerce checkout url?

Ok, it's known
add_filter( 'woocommerce_get_checkout_url',
function ( $checkout_url ) {
return '/checkout2/';
}, 300);
and I get to /checkout2 after pressing "Add to cart" button. But there's a 404!
How to make WC process this new url as checkout? I should do it dynamically, depending on the source of the traffic. There actually will be a number of urls.
You would need an actual page with the checkout shortcode inside I believe, Woocommerce won't generate pages that don't exist just be filtering it's checkout url.
You seem to be changing the url successfully but the url you're changing to doesn't exist.

How to force WordPress Gutenberg to update the featured image after saving the post?

I am working on a plugin that automatically attaches a featured image to a WordPress post after save (i.e. programmatically not using the Media Selector). The plugin uses the add_action( 'save_post_post', 'myFunction'); hook to save the image to the post.
The Gutenberg UI does not update the featured image thumbnail in the metabox on the right column.
I have tested and verified that the image is successfully updated and attached to the post, and does show if you manually reload the page.
From what I can tell, I need to tell Gutenberg the featured image has been changed in order for it to be updated in the view.
I have been unable to locate a hook or action I can use to trigger such a refresh after the user presses the "Save" button.
What is the appropriate way accomplish this refresh (from within my plugin PHP file)?
The way I see it, WordPress takes care of the update for you. Maybe you didn't use the right hook?
When I use the following, my posts have a default thumbnail, whenever I open a new plugin page:
function custom_add_thumbnail( $post_ID ) {
set_post_thumbnail($post_ID, 67);
return $post_ID;
}
add_action( 'save_post', 'custom_add_thumbnail' );
If this doesn't help, please share your code, maybe in pastebin, so I can investigate further.

Load Wordpress template based on page you are leaving

I want to be able to load the same post in Wordpress with a different page template based upon what URL a user has left to view the post.
So, if I have a post called "Post 1", and I click on it from a path such as www.mysite.com/flowers, then the post is loaded using the 'single-flowers.php' template. However, if the same post is selected from the page www.mysite.com/basketball, then the same page content is loaded, but with the page template 'single-basketball.php'. On the back end of Wordpress, the author can select the categories 'basketball' and 'flowers' to ensure the post displays in the correct places on the website.
Is this possible?
You can use $_SERVER['HTTP_REFERER'] to grab the prev url
$ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';
$regex = '/mysite.com\/flowers\//';
if (!empty($ref) && preg_match($regex, $ref)) {
get_template_part('single', 'flowers');
}

WordPress - Custom Post Type Entry Won't Load Into A Page

I created a very basic custom post type in my WP site to hold events. Basically, a user can input an event title, some information about the event and the date.
Currently, the only time the events are being displayed are in my sidebar where I just pull the title and date of the upcoming events.
However, I want to be able to allow the user to also click on the title of the link to lead to the event's individual page. I tried previewing my custom post type event and it kept leading me to my 404.php page. The events don't seem to load into a page at all.
I'm hoping this is a small property that I didn't set when I registered my post type. Any help?
Wordpress has incorporated custom post types into the template hierarchy and you have access to them at single-$posttype.php and archive-$posttype.php.
If you create these templates and your posts don't show up in the loop, you need to reset your permalinks/flush your rewrite rules.
As well, it would help to see how you are registering your post types, as in order for your archive-$posttype.php to be available you need to call has_archive => true in your arguments.
What i've done when i needed it:
Add this code in the same function that create your post type:
add_action("template_redirect", array(&$this, 'template_redirect'));
function template_redirect() {
global $wp;
if ($wp->query_vars["post_type"] == "events")
{
include(TEMPLATEPATH . "/events.php");
die();
}
}
Then, just create events.php with the_loop (like single.php)!
Hope it helps
[]'s

Resources