dongyo1818 2017-06-23 07:55
浏览 28

Wordpress Metaboxes.php

I am new to this metaboxes.php file, where all the content for the wordpress takes place.

I have a section of Metaboxes.php

array(
    'args' => array(
        'post_type' => 'xx_property',
        'numberposts' => -1,
        'post_status' => array(
            'publish'
        ),
    ),
    'data' => 'posts',
    'id' => 'xx_realtor',
    'multi' => true,
    'title' => __( 'view', 'xx_posts' ),
    'type' => 'select',
),

Here, this is a select box and select all the realtor who has post_status as publish, but I need to see if the realtor is active or nor. that's in id=xx_active.

instead of post_status, I need to point this to saying if the realtor is active show the list.

Can anyone has any suggestions?

  • 写回答

1条回答 默认 最新

  • doubaoguo7469 2017-06-23 10:07
    关注

    Add new meta box for post as a realtor and set this value as active or inactive.

    Refer below example code for custom meta box creation,

    // Post offer box
     add_action( 'add_meta_boxes', 'post_offer' );
     function post_offer() {
         add_meta_box(
             'post_offer',
             __( 'Price', 'agrg' ),
             'post_offer_content',
             'post',
             'side',
             'high'
         );
     }
    
     function post_offer_content( $post ) {
       wp_nonce_field( 'myplugin_meta_boxeee', 'myplugin_meta_box_nonceeee' );
       $post_offer = get_post_meta( $post->ID, 'post_offer', true );
       echo '<label for="post_offer"></label>';
       echo '<input type="text" id="post_offer" name="post_offer" 
       placeholder="'._e('Enter price here','agrg').'" value="';
       echo $post_offer;
       echo '">';
    
     }
    
    
     add_action( 'save_post', 'post_offer_save' );
     function post_offer_save( $post_id ) {
      global $post_offer;
      if ( ! isset( $_POST['myplugin_meta_box_nonceeee'] ) ) 
      {
        return;
      }
      if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonceeee'], 'myplugin_meta_boxeee' ) ) 
      {
       return;
      }
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
       return;
      }
    
      if(isset($_POST["post_offer"]))
      $post_offer = $_POST['post_offer'];
    
      update_post_meta( $post_id, 'post_offer', $post_offer );
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值