简体   繁体   English

Wordpress自定义字段(选择)以发布

[英]Wordpress custom field (select) to posts

I'm trying to understand plugins by making one. 我正在尝试通过制作一个插件来理解插件。 It puts a new menu to Wordpress Admin menu "Propagandas (ads)", which creates a post type "propaganda_item". 它将新菜单放入Wordpress Admin菜单“ Propagandas(ads)”,该菜单创建一个帖子类型“ propaganda_item”。

Since I need the user to choose a State/City for each "Propaganda", I've made an SQL table with City/State. 由于我需要用户为每个“宣传”选择一个州/城市,因此我制作了一个带有“城市/州”的SQL表。

So far, so good, but now I don't know how to put the php select combobox in the "Propaganda" edit page. 到目前为止,还算不错,但是现在我不知道如何在“宣传”编辑页面中放置php select组合框。 Example of what I mean 我的意思的例子

Actually I know how to populate the Select, but not how to put it within the post through my plugin. 实际上,我知道如何填充Select,但不知道如何通过我的插件将其放入帖子中。

Oh, and here is my plugin code: 哦,这是我的插件代码:

<?php 
/*
Plugin Name: Frankec
Plugin URI: 
Description: propagandas
Version:1
Author URI:
*/?>

<?php// Registra Propagandas

function register_cpt_Propagandas() {

$labels = array(
    'name' => _x( 'Propagandas', 'propaganda_item' ),
    'singular_name' => _x( 'Propagandas', 'propaganda_item' ),
    'add_new' => _x( 'Nova', 'propaganda_item' ),
    'add_new_item' => _x( 'Adicionar Propagandas', 'propaganda_item' ),
    'edit_item' => _x( 'Editar Propagandas', 'propaganda_item' ),
    'new_item' => _x( 'Nova Propagandas', 'propaganda_item' ),
    'view_item' => _x( 'Ver Propagandas', 'propaganda_item' ),
    'search_items' => _x( 'Procurar Propagandas', 'propaganda_item' ),
    'not_found' => _x( 'Nenhuma Propaganda encontrada', 'propaganda_item' ),
    'not_found_in_trash' => _x( 'Nenhuma Propaganda encontrada no lixo', 'propaganda_item' ),
    'parent_item_colon' => _x( 'Propagandas-pai:', 'propaganda_item' ),
    'menu_name' => _x( 'Propagandas', 'propaganda_item' ),
);

$args = array(
    'labels' => $labels,
    'hierarchical' => true,
    'description' => 'Propagandas por Cateoria',
    'supports' => array( 'title', 'editor', 'thumbnail'),
    'taxonomies' => array( 'genres' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 5,
    'menu_icon' => 'dashicons-images-alt2',
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'post'
);

register_post_type( 'propaganda_item', $args );
}

add_action( 'init', 'register_cpt_Propagandas' );


function remove_menus(){


 remove_menu_page( 'edit-comments.php' );          //Comments    

}
add_action( 'admin_menu', 'remove_menus' );



?>

Thanks in advance guys! 在此先感谢大家! =) =)

I think you're doing it the hard way. 我认为您正在这样做。 You don't have to create any SQL tables. 您不必创建任何SQL表。 Try searching how to add a custom select field to CPT. 尝试搜索如何将自定义选择字段添加到CPT。 You could use a plugin like Advanced Custom Fields or if you prefer to code it on your own, use the Custom Meta Box framework . 您可以使用“ 高级自定义字段”之类的插件,或者如果您希望自己编写代码,请使用“ 自定义元框”框架

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM