WP Job manager Location dropdown - php

Im using the WP Job Manager plug on my website. On the home page im using the Hero search filter that has the location search input, that is a text input at the moment but I would like to change it to a dropdown with set options. I've been able to easily change the location text input to a dropdown with the chosen options.
I hit search, nothing changes in the job listings below.
I've tried to change the way the input is handled in the source files but with no luck. When i output the result of the 'Location' input on the job listing page but it keeps coming back as an empty field.
I have no idea what els to try to accomplish the desired result any more so any help or input would be appreciated.
The code below is how my part-job-filters.php code.
<?php
if ( ! class_exists( 'WP_Job_Manager' ) ) {
return;
}
$keywords = '';
$location = array();
$selected_category = array();
if ( ! empty( $_GET['search_keywords'] ) ) {
$keywords = sanitize_text_field( $_GET['search_keywords'] );
}
// Old Location input field
// if ( ! empty( $_GET['search_location'] ) ) {
// $location = sanitize_text_field( $_GET['search_location'] );
// }
if ( ! empty( $_GET['search_location'] ) ) {
$location = absint( $_GET['search_location'] );
}
if ( ! empty( $_GET['search_category'] ) ) {
if ( is_array( $_GET['search_category'] ) ) {
$selected_category = absint( reset( $_GET['search_category'] ) );
} else {
$selected_category = absint( $_GET['search_category'] );
}
$_GET['search_category'] = $selected_category;
}
if ( is_tax( 'job_listing_category' ) ) {
$term = get_queried_object();
$_GET['search_category'] = $selected_category = array( $term->term_id );
}
?>
<div class="form-filter">
<div class="form-filter-header">
×<span class="sr-only"> <?php esc_html_e( 'Dismiss filters', 'specialty' ); ?></span>
</div>
<?php
$has_categories = true;
$count = wp_count_terms( 'job_listing_category', array(
'hide_empty' => 1, // Hide empty, as they are not displayed by the dropdown anyway.
) );
if ( is_wp_error( $count ) || 0 === intval( $count ) || is_tax( 'job_listing_category' ) ) {
$has_categories = false;
}
$col_classes = array(
'keywords' => 'col-lg-3 col-xs-12',
'location' => 'col-lg-3 col-xs-12',
'category' => 'col-lg-3 col-xs-12',
'button' => 'col-lg-3 col-xs-12',
);
if ( ! get_option( 'job_manager_enable_categories' ) || ! $has_categories ) {
$col_classes = array(
'keywords' => 'col-lg-4 col-xs-12',
'location' => 'col-lg-4 col-xs-12',
'category' => '',
'button' => 'col-lg-3 push-lg-1 col-xs-12',
);
}
?>
<div class="container">
<div class="row">
<div class="<?php echo esc_attr( $col_classes['keywords'] ); ?>">
<label for="job-keywords" class="sr-only"><?php esc_html_e( 'Job Keywords', 'specialty' ); ?></label>
<input type="text" id="job-keywords" name="search_keywords" placeholder="<?php esc_attr_e( 'Keywords', 'specialty' ); ?>" value="<?php echo esc_attr( $keywords ); ?>">
</div>
<div class="<?php echo esc_attr( $col_classes['location'] ); ?>">
<label for="job-location" class="sr-only"><?php esc_html_e( 'Job Location', 'specialty' ); ?></label>
<div class="ci-select">
<select name="search_location" id="job-location" data-no_results_text="No results match" data-multiple_text="Select Some Options">
<option value="0">Select a location</option>
<option value="Eastern Cape">Eastern Cape</option>
<option value="Free State">Free State</option>
<option value="Gauteng">Gauteng</option>
<option value="kwazulu natal">kwazulu natal</option>
<option value="Limpopo">Limpopo</option>
<option value="Mpumalanga">Mpumalanga</option>
<option value="North West">North West</option>
<option value="Northern Cape">Northern Cape</option>
<option value="Western Cape">Western Cape</option>
<option value="Africa">Africa</option>
<option value="International">International</option>
<option value="All locations">All locations</option>
</select>
</div>
</div>
<?php if ( get_option( 'job_manager_enable_categories' ) && $has_categories ) : ?>
<div class="<?php echo esc_attr( $col_classes['category'] ); ?>">
<label for="job-category" class="sr-only"><?php esc_html_e( 'Job Category', 'specialty' ); ?></label>
<div class="ci-select">
<?php
$multiple = get_option( 'job_manager_enable_default_category_multiselect' );
job_manager_dropdown_categories( array(
'taxonomy' => 'job_listing_category',
'hierarchical' => 1,
'show_option_all' => $multiple ? false : esc_html__( 'Any category', 'specialty' ),
'name' => 'search_category',
'orderby' => 'name',
'selected' => $selected_category,
'multiple' => $multiple,
) );
?>
</div>
</div>
<?php endif; ?>
<div class="<?php echo esc_attr( $col_classes['button'] ); ?>">
<button class="btn btn-block btn-jobs-filter" type="submit"><?php esc_html_e( 'Search', 'specialty' ); ?></button>
</div>
</div>
</div>
</div>
I might be approaching this the wrong way, if so please could someone advise what the right way is of approaching this.

Replace id in select element, id="job-location" to id="search_location".

Related

Custom taxonomy archive showing all posts

I have a custom post type 'vacatures' with two custom taxonomies 'type' and 'locatie'. I created an archive page to display all the posts, but now when I view the link for all the posts belonging to a specific 'type', it just shows all the posts like the archive page.
How can I solve this, making sure I can still make the filters work?
archive-vacatures.php:
<?php get_header(); ?>
<div class="jobs__banner">
<h1><?php _e( 'VACATURES', 'ago' ) ?></h1>
</div>
<div class="vacatures__archief">
<?php
$types = get_terms([ 'taxonomy' => 'type' ]);
$locations = get_terms([ 'taxonomy' => 'locatie']);
$postsQuery = [
'order' => 'DESC',
'post_type' => 'vacatures',
'posts_per_page' => -1,
'tax_query' => []
];
if(array_key_exists('type_id', $_GET) && $_GET['type_id']) {
$postsQuery['tax_query'][] = [
'taxonomy' => 'type',
'field' => 'term_id',
'terms' => [$_GET['type_id']]
];
}
if(array_key_exists('locatie_id', $_GET) && $_GET['locatie_id']) {
$postsQuery['tax_query'][] = [
'taxonomy' => 'locatie',
'field' => 'term_id',
'terms' => [$_GET['locatie_id']]
];
}
if(array_key_exists('query', $_GET) && $_GET['query']) {
$postsQuery['s'] = $_GET['query'];
}
query_posts($postsQuery); ?>
<form class="vacature__filter">
<input type="text" name="query" placeholder="Search.." />
<select name="type_id">
<option value="">-- <?php _e( 'Alle types', 'ago' ) ?> --</option>
<?php foreach($types as $type) {
$selected = array_key_exists('type_id', $_GET) && $_GET['type_id'] == $type->term_id ? 'selected' : '';
echo "<option value='{$type->term_id}' {$selected}>{$type->name}</option>";
} ?>
</select>
<select name="locatie_id">
<option value="">-- <?php _e( 'Alle locaties', 'ago' ) ?> --</option>
<?php foreach($locations as $locatie) {
$selected = array_key_exists('locatie_id', $_GET) && $_GET['locatie_id'] == $locatie->term_id ? 'selected' : '';
echo "<option value='{$locatie->term_id}' {$selected}>{$locatie->name}</option>";
} ?>
</select>
<button type="submit">Zoek</button>
</form>
<?php if ( have_posts() ) { ?>
<?php
while ( have_posts() ) {
the_post();
?>
<article id="vacature-<?php the_ID(); ?>" <?php post_class(); ?>>
<a class="vacature__item" href="<?php the_permalink(); ?>">
<h2 class="vacature__title"><?php the_title(); ?></h2>
<h4 class="vacature__company"><?php echo get_field('vacature_bedrijf') ?> - <?php $terms = get_the_terms( $post->ID , 'type' ); $i = 1; foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'type' ); if( is_wp_error( $term_link ) ) continue; echo $term->name; echo ($i < count($terms))? ", " : ""; $i++; } ?></h4>
<h6 class="vacature__location"><?php $terms = get_the_terms( $post->ID , 'locatie' ); foreach ( $terms as $term ) { echo $term->name; } ?></h6>
</a>
</article>
<?php
}
}
?>

'key' meta_query not working custom advanced search (WordPress)

Been trying for hours now and have almost got to breaking point. Tried so many different things but can't seem to get my custom search bar to query results by a pre-defined select price range. I am using Advanced Custom Fields to add the meta tag 'investmentprice' to my custom post type called 'investments'. I feel like it's to do with WordPress not picking up the correct 'key' in my meta_query, even though I have changed this numerous times now.
Here's the code for the config bar:
<div class="config_bar cf">
<form method="get" role="search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<input type="hidden" name="s" value="">
<input type="hidden" name="post_type" value="investments" />
<div class="col">
<?php
$taxonomy = 'type';
$args = array( 'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
);
$tax_terms = get_terms($taxonomy, $args);
?>
<span class="label_inner">Investment Type</span>
<select name="type" id="type" class="postform standard">
<option value="" selected="selected">All Investment Types </option>
<?php if($tax_terms): ?>
<?php foreach ($tax_terms as $tax_term): ?>
<?php $title = $tax_term->name;
?>
<option value="<?php echo $tax_term->slug; ?>"><?php echo $title; ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div><!-- col -->
<div class="col">
<span class="label_inner"><?php _e('Select Country','opencloud');?></span>
<select class="postform standard country " name="country" id="country">
<option value=""><?php _e('All Countries','opencloud');?></option>
<?php
// Display only parents here .
$terms = get_terms( array(
// Put your taxonomy name here.
'taxonomy' => 'location',
'parent' => 0,
'hide_empty' => false
) );
foreach ($terms as $term){?>
<!-- We are going to send value for $_POST and data-makeId's TERM_ID for ajax request -->
<option value="<?php echo $term->slug;?>" data-countryId="<?php echo $term->term_id ?>"><?php echo $term->name;?></option>
<?php
wp_reset_query(); // if you're not in your main loop! otherwise you can skip this
} ?>
</select>
</div><!-- col -->
<script type="text/javascript">
$( document ).ready(function() {
$('#country').change(function(){
var $mainCat= $(this).find(':selected').attr('data-countryId');
if ($mainCat != '0' ){
// call ajax
$("#city").empty();
$.ajax
(
{
url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
type:'POST',
data:'action=get_city_lists_ajax&main_catid=' + $mainCat,
beforeSend:function()
{
},
success:function(results)
{
$("#loading_bar").hide();
$("#city").removeAttr("disabled").trigger('change.select2');
$("#city").append(results).trigger('change.select2');
}
}
);
}
});
});
</script>
<div class="col">
<span class="label_inner"><?php _e('Select City','opencloud');?></span>
<select class="postform standard city " name="city" id="city" disabled>
<option value="<?php echo $term->slug;?>"><?php _e('All Cities','opencloud');?></option>
</select>
</div><!-- col -->
<div class="col">
<span class="label_inner">Select Price</span>
<select class="postform standard price" name="price" id="price">
<option value="">All Prices</option>
<option value="500-1000">£500-£1000</option>
<option value="1000-1500">£1000-£1500</option>
<option value="1500-2000">£1500-£2000</option>
<option value="2000-5000">£1500-£2000</option>
<option value="5000-10000">£5000-£10,000</option>
</select>
</div><!-- col -->
<div class="col">
<button class="search_submit" type="submit">Search</button>
</div><!-- col -->
</form>
And here's my advanced search query function:
function advanced_search_query( $query ) {
if ( isset( $_REQUEST['search'] ) && $_REQUEST['search'] == 'advanced' && !is_admin() && $query->is_search && $query->is_main_query() ) {
// limit query for custom post type
$query->set( 'post_type', 'investments' );
// Get query strings from URL and store the min a variable
$_type = $_GET['type'] != '' ? $_GET['type'] : '';
$_country = $_GET['country'] != '' ? $_GET['country'] : '';
$_city = $_GET['city'] != '' ? $_GET['city'] : '';
$_price = $_GET['price'] != '' ? $_GET['price'] : '';
if( $_price != '' ) {
$metaquery = array(
array(
'key' => 'investmentprice',
'terms' => $_price,
'compare' => 'BETWEEN'
)
);
$query->set( 'meta_query', $metaquery );
}
// if type is not empty limit the taxonomy to the specified
if( $_type != '' ) {
$taxquery = array(
array(
'taxonomy' => 'type',
'field' => 'slug',
'terms' => $_type,
'operator'=> 'IN'
)
);
$query->set( 'tax_query', $taxquery );
}
// if country is not empty limit the taxonomy to the specified
if( $_country != '' ) {
$taxquery = array(
array(
'taxonomy' => 'country',
'field' => 'slug',
'terms' => $_country,
'operator'=> 'IN'
)
);
$query->set( 'tax_query', $taxquery );
}
// if city is not empty limit the taxonomy to the specified
if( $_city != '' ) {
$taxquery = array(
array(
'taxonomy' => 'city',
'field' => 'slug',
'terms' => $_city,
'operator'=> 'IN'
)
);
$query->set( 'tax_query', $taxquery );
}
return; // always return
}
}
Also, here's a screenshot of the Advanced Custom Field:
Unless there are any other issues, this should be a small fix. You are using the array key 'terms' instead of 'value' in your meta query. According to the WordPress Codex, a nested array of args for a meta query should use value, like this:
$metaquery = array(
array(
'key' => 'investmentprice',
'value' => $_price,
'compare' => 'BETWEEN'
)
);
$query->set( 'meta_query', $metaquery );
Hope that helps..

Wordpress Meta Box Form Data Not Saving

My plugin is about adding FAQs to your desired page.
I have added a form within a metabox in the 'Add New Question'.
When I feed values in the form, the form data does save in
the database, but does not retain or show the values (selected)
in the form when the page updates/publishes.
Instead, the form shows the previous non-selected values (even though the
selected values do show up in the database).
<?php
function faq_manage_things($post)
{
global $post;
$post_id= $post->ID;
wp_nonce_field(basename(__FILE__),'faqs_questions_nonce');
$faq_stored_meta= get_post_meta($post->ID);
?>
<div class="wrap">
<p>
<label for="meta-select" class="prfx-row-title"><?php _e( 'Example Select Input', 'prfx-textdomain' )?></label>
<select name="meta-select" id="meta-select">
<option value="select-one" <?php if ( isset ( $prfx_stored_meta['meta-select'] ) ) selected( $prfx_stored_meta['meta-select'][0], 'select-one' ); ?>><?php _e( 'One', 'prfx-textdomain' )?></option>';
<option value="select-two" <?php if ( isset ( $prfx_stored_meta['meta-select'] ) ) selected( $prfx_stored_meta['meta-select'][0], 'select-two' ); ?>><?php _e( 'Two', 'prfx-textdomain' )?></option>';
</select>
</p>
<!-- TEXT AREA -->
<p>
<label for="meta-textarea" class="prfx-row-title"><?php _e( 'Example Textarea Input', 'prfx-textdomain' )?></label>
<textarea name="meta-textarea" id="meta-textarea"><?php if ( isset ( $prfx_stored_meta['meta-textarea'] ) ) echo $prfx_stored_meta['meta-textarea'][0]; ?></textarea>
</p>
<!-- CHECKBOXES -->
<p>
<span class="prfx-row-title"><?php _e( 'Example Checkbox Input', 'prfx-textdomain' )?></span>
<div class="prfx-row-content">
<label for="meta-checkbox">
<input type="checkbox" name="meta-checkbox" id="meta-checkbox" value="yes" <?php if ( isset ( $prfx_stored_meta['meta-checkbox'] ) ) checked( $prfx_stored_meta['meta-checkbox'][0], 'yes' ); ?> /><?php _e( 'Checkbox label', 'prfx-textdomain' )?>
</label>
<label for="meta-checkbox-two">
<input type="checkbox" name="meta-checkbox-two" id="meta-checkbox-two" value="yes" <?php if ( isset ( $prfx_stored_meta['meta-checkbox-two'] ) ) checked( $prfx_stored_meta['meta-checkbox-two'][0], 'yes' ); ?> /><?php _e( 'Another checkbox', 'prfx-textdomain' )?>
</label>
</div>
</p>
</div>
<?php
}
global $post;
function faq_meta_save( $post_id ) {
global $post;
$post_id= $post->ID;
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'faqs_questions_nonce' ] ) && wp_verify_nonce( $_POST['faqs_questions_nonce'],basename(__FILE__)) )? 'true' : 'false';
if ( $is_autosave || $is_revision || !$is_valid_nonce )
{return;} //exit
if( isset( $_POST[ 'meta-select' ] ) )
{ update_post_meta( $post_id, 'meta-select', $_POST[ 'meta-select' ] ); }
if( isset( $_POST[ 'meta-textarea' ] ) ) {
update_post_meta( $post_id, 'meta-textarea', sanitize_text_field($_POST[ 'meta-textarea' ]) ); }
// Checks for input and saves
if( isset( $_POST[ 'meta-checkbox' ] ) ) {
update_post_meta( $post_id, 'meta-checkbox', 'yes' );}
else {
update_post_meta( $post_id, 'meta-checkbox', '' ); }
// Checks for input and saves
if( isset( $_POST[ 'meta-checkbox-two' ] ) ) {
update_post_meta( $post_id, 'meta-checkbox-two', 'yes' );}
else {
update_post_meta( $post_id, 'meta-checkbox-two', '' ); }
}
add_action('save_post','faq_meta_save');
You have to check if you have the meta_key duplicated in the database for the same post_id. Also, I recommend you to use underscores instead of hyphens in the meta_key names. Try this code where the meta_data of the post_id is deleted and then is added the new value.
Try this:
<?php
function faq_manage_things($post)
{
global $post;
$post_id= $post->ID;
wp_nonce_field(basename(__FILE__),'faqs_questions_nonce');
$faq_stored_meta= get_post_meta($post->ID);
?>
<div class="wrap">
<p>
<label for="meta-select" class="prfx-row-title"><?php _e( 'Example Select Input', 'prfx-textdomain' )?></label>
<select name="meta-select" id="meta-select">
<option value="select-one" <?php if ( isset ( $prfx_stored_meta['meta_select'] ) ) selected( $prfx_stored_meta['meta_select'][0], 'select-one' ); ?>><?php _e( 'One', 'prfx-textdomain' )?></option>';
<option value="select-two" <?php if ( isset ( $prfx_stored_meta['meta_select'] ) ) selected( $prfx_stored_meta['meta_select'][0], 'select-two' ); ?>><?php _e( 'Two', 'prfx-textdomain' )?></option>';
</select>
</p>
<!-- TEXT AREA -->
<p>
<label for="meta-textarea" class="prfx-row-title"><?php _e( 'Example Textarea Input', 'prfx-textdomain' )?></label>
<textarea name="meta-textarea" id="meta-textarea"><?php if ( isset ( $prfx_stored_meta['meta_textarea'] ) ) echo $prfx_stored_meta['meta_textarea'][0]; ?></textarea>
</p>
<!-- CHECKBOXES -->
<p>
<span class="prfx-row-title"><?php _e( 'Example Checkbox Input', 'prfx-textdomain' )?></span>
<div class="prfx-row-content">
<label for="meta-checkbox">
<input type="checkbox" name="meta-checkbox" id="meta-checkbox" value="yes" <?php if ( isset ( $prfx_stored_meta['meta_checkbox'] ) ) checked( $prfx_stored_meta['meta_checkbox'][0], 'yes' ); ?> /><?php _e( 'Checkbox label', 'prfx-textdomain' )?>
</label>
<label for="meta-checkbox-two">
<input type="checkbox" name="meta-checkbox-two" id="meta-checkbox-two" value="yes" <?php if ( isset ( $prfx_stored_meta['meta_checkbox_two'] ) ) checked( $prfx_stored_meta['meta_checkbox_two'][0], 'yes' ); ?> /><?php _e( 'Another checkbox', 'prfx-textdomain' )?>
</label>
</div>
</p>
</div>
<?php
}
global $post;
function faq_meta_save( $post_id ) {
global $post;
$post_id= $post->ID;
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'faqs_questions_nonce' ] ) && wp_verify_nonce( $_POST['faqs_questions_nonce'],basename(__FILE__)) )? 'true' : 'false';
if ( $is_autosave || $is_revision || !$is_valid_nonce )
{return;} //exit
if( isset( $_POST[ 'meta-select' ] ) ) {
remove_post_meta( $post_id, 'meta_select', $_POST[ 'meta-select' ] );
add_post_meta( $post_id, 'meta_select', $_POST[ 'meta-select' ] );
}
if( isset( $_POST[ 'meta-textarea' ] ) ) {
remove_post_meta( $post_id, 'meta_textarea', sanitize_text_field($_POST[ 'meta-textarea' ]) );
add_post_meta( $post_id, 'meta_textarea', sanitize_text_field($_POST[ 'meta-textarea' ]) );
}
// Checks for input and saves
if( isset( $_POST[ 'meta-checkbox' ] ) ) {
remove_post_meta( $post_id, 'meta_checkbox', 'yes' );
add_post_meta( $post_id, 'meta_checkbox', 'yes' );
}
else {
remove_post_meta( $post_id, 'meta_checkbox');
}
// Checks for input and saves
if( isset( $_POST[ 'meta-checkbox-two' ] ) ) {
remove_post_meta( $post_id, 'meta_checkbox-two', 'yes' );
add_post_meta( $post_id, 'meta_checkbox-two', 'yes' );
}
else {
remove_post_meta( $post_id, 'meta_checkbox-two');
}
}
add_action('save_post','faq_meta_save');

Wordpress - Custom post image on frontend doesn't upload

I've one form to upload an attachment file
<form id="post-job-form" class="frontend-form" action="" method="post" enctype="multipart/form-data" role="form">
<?php
$status_message = '';
if( isset( $_GET['message'] ) ){
$status_message = $_GET['message'];
}
// check if user have post a company
$check = get_posts( array( 'post_type' => 'company', 'author' => get_current_user_id() ) );
if( $check == null ){
$status_message = '6';
}//endif;
jobboard_set_post_message( $status_message );
?>
<div class="form-group">
<label for="sallary_periode"><?php _e( 'Salaire Periode', 'jobboard' ); ?></label>
<select name="sallary_periode" id="sallary_periode" class="form-control">
<?php
$sallary_periode = array(
'hourly' => 'Hourly',
'daily' => 'Daily',
'weekly' => 'Weekly',
'monthly' => 'Monthly'
);
foreach( $sallary_periode as $periode_key => $periode_value ) {
$selected = '';
if( $default['sallary_periode'] == $periode_key ){
$selected = 'selected';
}
echo '<option value="'.$periode_key.'" '.$selected.'>'.esc_attr($periode_value).'</option>';
}
?>
</select>
</div><!-- /.form-group -->
<div class="form-group">
<label for="job_img"><?php _e( 'L`image (en option)', 'jobboard' ); ?></label>
<?php
if( isset($_GET['action']) && $_GET['action'] == 'edit' ){
$edit = get_post( $_GET['jid'] );
$jobimag = get_post_meta( $edit->ID, 'jbchild_meta_job_image', true );
if(!empty($jobimag)){
echo '<img src="' . $jobimag . '">';
}//!empty
}//endif;
?>
<input class="" type="file" name="job_photo" id="job_photo" accept="image/*" />
<span class="help-block"><?php _e( 'Télécharger éventuellement votre image pour les candidats pour voir', 'jobboard' ); ?></span>
</div><!-- /.form-group -->
<?php
if( isset( $_GET['action'] ) && $_GET['action'] == 'edit' ){
$button_text = __( 'Update Job', 'jobboard' );
?>
<input type="hidden" name="form_type" id="form_type" value="edit_post_job" />
<input type="hidden" name="post_id" id="post_id" value="<?php echo esc_attr( $default['post_id'] ); ?>" />
<?php
}else{
$button_text = __( 'Post A Job', 'jobboard' );
?>
<input type="hidden" name="form_type" id="form_type" value="post_job" />
<?php
}
?>
<input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( get_current_user_id() ); ?>" />
<button type="submit" name="submit" class="btn btn-post-resume"><?php echo esc_attr( $button_text ); ?></button>
</form>
And this is my function:
function jobboard_post_job_123( $data = array(), $files = array(), $update = false ){
$post_status = 'publish';
if(jobboard_option('enable_highlight_package_job') == '1'){
$post_status ='publish';
}
$job_args = array(
'post_content' => $data['job_description'],
'post_title' => $data['job_title'],
'post_status' => $post_status,
'post_type' => 'job',
'post_author' => $data['user_id'],
);
$message = '1';
if( $update ){
$job_args['ID'] = $data['post_id'];
$job_args['post_status'] = get_post_status( $data['post_id'] );
$message = '2';
}
$job_id = wp_insert_post( $job_args );
if($job_id){
if( isset( $data['job_region'] ) ){
wp_set_object_terms( $job_id, $data['job_region'], 'job_region' );
}
if( isset( $data['job_type'] ) ){
wp_set_object_terms( $job_id, $data['job_type'], 'job_type' );
}
if( isset( $data['job_category'] ) ){
wp_set_object_terms( $job_id, $data['job_category'], 'job_category' );
}
// Job Company Metabox
update_post_meta( $job_id, '_jboard_job_company', $data['job_company'] );
// Job Experience Metabox
update_post_meta( $job_id, '_jboard_job_experiences', $data['job_experience'] );
// Job Salary Metabox
update_post_meta( $job_id, '_jboard_job_sallary', $data['job_sallary'] );
// Job Salary Periode
update_post_meta( $job_id, '_jboard_sal_periode', $data['sallary_periode'] );
// Job Summary Metabox
update_post_meta( $job_id, '_jboard_job_summary', $data['job_summary'] );
// Job Overview Metabox
update_post_meta( $job_id, '_jboard_job_overview', $data['job_overview'] );
if( !empty( $files['job_photo']['name'] ) ){
$job_img = jobboard_file_upload( $files['job_photo'], 'file' );
$old_job_img = get_post_meta( $job_id, 'jbchild_meta_job_image', true );
if($job_img){
//update_post_meta( $job_id, 'jbchild_meta_job_image', $job_img['url'], $old_job_img );
update_post_meta( $job_id, 'jbchild_meta_job_image', 'http://www.soslivreur.fr/wp-content/uploads/2016/04/20160316_174725.jpg' );
}
}
// Job metabox data set
$job_meta = array(
'_jboard_sal_periode'
);
update_post_meta( $job_id, 'jobboard_job_mb_fields', $job_meta );
wp_redirect( esc_url(add_query_arg( array( 'action' => 'edit', 'jid' => $job_id, 'message' => $message ) ) ) );
exit;
}
}
I have a problem. When I'm submitting this form others field can insert to database but an image can't insert to database.
How to fix my code? Thank you
please replace this line of code in your function file function name is jobboard_post_job_123
if( !empty( $files['job_photo']['name'] ) ){
$job_img = jobboard_file_upload( $files['job_photo'], 'file' );
//$old_job_img = get_post_meta( $job_id, 'jbchild_meta_job_image', true );
if($job_img != ''){
update_post_meta( $job_id, 'jbchild_meta_job_image', 'http://www.soslivreur.fr/wp-content/uploads/2016/04/20160316_174725.jpg' );
}
}
And then check it's work or not becuase you had predefine Old job image on that.

Wordpress Theme Options Page - Radio Buttons not updating correctly

I am currently working on the Theme Options Page of my Wordpress Theme.
As a base I'm using the "SAMPLE WORDPRESS THEME OPTIONS PAGE" by Ian Steward:
The Situation:
I've implemented two sets of radio-buttons like so:
The Problem:
They work as planned, the chosen options are applied.
Only problem: after saving the chosen radio buttons aren't selected anymore.
For the image above: If I would change both radio buttons and click save only the very first radio button is selected, after the page has loaded again.
The Code:
From the theme-options.php:
// Normal/Fixed Navigation Options
$fixed_navigation_options = array(
'Normal' => array(
'value' => ' ',
'label' => __( 'Normal', 'arrowcatch' )
),
'Fixed' => array(
'value' => 'is-fixed',
'label' => __( 'Fixed', 'arrowcatch' )
)
);
// Full-width/Contained Navigation Options
$contained_navigation_options = array(
'Full-width' => array(
'value' => ' ',
'label' => __( 'Full-width', 'arrowcatch' )
),
'Contained' => array(
'value' => 'is-contained',
'label' => __( 'Contained', 'arrowcatch' )
)
);
function arrowcatch_theme_options_page() {
global $select_options, $fixed_navigation_options, $contained_navigation_options;
if ( ! isset( $_REQUEST['settings-updated'] ) )
$_REQUEST['settings-updated'] = false; ?>
<div class="wrap">
<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
<div class="updated fade">
<p><strong>Options saved!</strong></p>
</div>
<?php endif; ?>
<!-- Normal/Fixed Navigation -->
<tr valign="top"><th scope="row"><?php _e( 'Navigation Normal/Fixed', 'arrowcatch' ); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e( 'Navigation Normal/Fixed', 'arrowcatch' ); ?></span></legend>
<?php
if ( ! isset( $checked ) )
$checked = '';
foreach ( $fixed_navigation_options as $option ) {
$fixed_navigation_setting = $options['fixed_navigation'];
if ( '' != $fixed_navigation_setting ) {
if ( $options['fixed_navigation'] == $option['value'] ) {
$checked = "checked=\"checked\"";
} else {
$checked = '';
}
}
?>
<label class="description"><input type="radio" name="arrowcatch_theme_options[fixed_navigation]" value="<?php esc_attr_e( $option['value'] ); ?>" <?php echo $checked; ?> /> <?php echo $option['label']; ?></label><br />
<?php
}
?>
</fieldset>
</td>
</tr>
<!-- Full-width/Contained Navigation -->
<tr valign="top"><th scope="row"><?php _e( 'Navigation Full-width/Contained', 'arrowcatch' ); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e( 'Navigation Full-width/Contained', 'arrowcatch' ); ?></span></legend>
<?php
if ( ! isset( $checked ) )
$checked = '';
foreach ( $contained_navigation_options as $option ) {
$contained_navigation_setting = $options['contained_navigation'];
if ( '' != $contained_navigation_setting ) {
if ( $options['fixed_navigation'] == $option['value'] ) {
$checked = "checked=\"checked\"";
} else {
$checked = '';
}
}
?>
<label class="description"><input type="radio" name="arrowcatch_theme_options[contained_navigation]" value="<?php esc_attr_e( $option['value'] ); ?>" <?php echo $checked; ?> /> <?php echo $option['label']; ?></label><br />
<?php
}
?>
</fieldset>
</td>
</tr>
Hope that's all the code thats needed.
Not sure what's going on there.
I'm very thankfull for any push in the right direction.
Thank you!

Categories