使用wp insert post无法在meta中保存复选框值?

时间:2015-07-09 03:50:06

标签: php wordpress checkbox

我试图通过add_post_meta添加复选框值,但没有运气..! 它保存在数据库中......但是当我在wordpress中打开帖子时,没有勾选复选框..!

所以,请查看我的代码,如果我做错了,请告诉我:

require_once("../rabotavbaku/wp-load.php");
// Create post object
$my_post = array(
  'post_title'    => $job_title,
  'post_content'  => "<strong>İş barədə məlumat</strong> :</br>".$job_description."</br><strong>Namizədə tələblər :</strong></br>".$requirements,
  'post_type'     => 'job_listing',
  'post_status'   => 'publish',
  'post_author'   => 0,
);

// Insert the post into the database
$post_id = wp_insert_post( $my_post );

add_post_meta($post_id, '_company_name', $company_name, true);
add_post_meta($post_id, '_application', $email, true);
add_post_meta($post_id, '_job_location', 'Baku', true);
add_post_meta($post_id, '_job_expires', $expire_date, true);
// This one is that checkbox meta but it isn't working
add_post_meta($post_id, 'tax_input[job_listing_type][]', 2,true);

1 个答案:

答案 0 :(得分:0)

试试这个请查看此图片以获取复选框。例如 enter image description here

<li><input type="checkbox" value="1" name="checkInt[]"><span>Economics</span></li>
<li><input type="checkbox" value="3" name="checkInt[]"><span>Science</span></li>    
require_once("../rabotavbaku/wp-load.php");
    // get values for check boxes
    $check = $_REQUEST['checkInt'];
    $q1=implode(',', $check);

    // Create post object
    $my_post = array(
      'post_title'    => $job_title,
      'post_content'  => "<strong>İş barədə məlumat</strong> :</br>".$job_description."</br><strong>Namizədə tələblər :</strong></br>".$requirements,
      'post_type'     => 'job_listing',
      'post_status'   => 'publish',
      'post_author'   => 0,
    );

    // Insert the post into the database
    $post_id = wp_insert_post( $my_post );

    add_post_meta($post_id, '_company_name', $company_name, true);
    add_post_meta($post_id, '_application', $email, true);
    add_post_meta($post_id, '_job_location', 'Baku', true);
    add_post_meta($post_id, '_job_expires', $expire_date, true);
    // This one is that checkbox meta but it isn't working
    add_post_meta($post_id, '_checked',$q1);