apply_filters( ‘jobrelay_wpcon_insert_job_post_args
‘, $args array, $job_data array )
In this article
Filters the array of arguments that is passed to the wp_insert_post
function when a new job is to be created or updated from the sent job data.
Parameters
$post
WP_Post
The current post object$update
bool
Whether this is a update (true) or a save (false)
More information
The filter is passed the array of arguments used by wp_insert_post
and therefore any of these arguments can be used.
Example usage
Ensure newly created JobRelay jobs are in draft
If you want to ensure that jobs created by JobRelay are set to a post status of draft
rather than publish
, the following code achieves this.
The code can be placed in a plugin, or in your themes functions.php
file.
<?php
/**
* Alters the args passed to wp_insert_post when a job is created.
*
* @param array $args The args passed to wp_insert_post.
* @param array $data The job data sent to the site.
*
* @return array The modified args.
*/
function hd_jobrelay_edit_insert_job_post_args( $args, $data ) {
// set the post status to draft.
$args['post_status'] = 'draft';
// return the args.
return $args;
}
add_filter( 'jobrelay_wpcon_insert_job_post_args', 'hd_jobrelay_edit_insert_job_post_args', 20, 2 );
In addition to this, you will also need to ensure that when JobRelay checks for an existing job with the same reference (so as not to duplicate the job post) it checks for draft jobs to.
The following function will achieve this.
<?php
/**
* Ensures that when checking for existing jobs with a reference
* that we check for both draft and published jobs.
*
* @param array $args The arguments to pass to the get_posts function.
* @param string $ref The reference to search for.
*
* @return array
*/
function hd_jobrelay_edit_get_job_by_reference_args( $args, $ref ) {
// set the post status to draft and publish.
$args['post_status'] = [ 'draft', 'publish' ];
// return the args.
return $args;
}
add_filter( 'jobrelay_wpcon_get_job_by_reference_args', 'hd_jobrelay_edit_get_job_by_reference_args', 10, 2 );