我已经创建了一个名为代理的自定义帖子类型。
我有一个列出所有代理的页面。
当我添加代理时,我有一系列可以填写的自定义元框,区域、专业、语言。。。
我想在前端添加一系列下拉框,这些下拉框将填充来自每个自定义元的所有术语。例如,regions dropbox将填充来自所有代理的所有区域。如果我在新区域中添加新代理,dropbox将自动拾取该代理。
感谢您的关注。
我已经创建了一个名为代理的自定义帖子类型。
我有一个列出所有代理的页面。
当我添加代理时,我有一系列可以填写的自定义元框,区域、专业、语言。。。
我想在前端添加一系列下拉框,这些下拉框将填充来自每个自定义元的所有术语。例如,regions dropbox将填充来自所有代理的所有区域。如果我在新区域中添加新代理,dropbox将自动拾取该代理。
感谢您的关注。
如果您尝试这样做,最终可能会查询相当大的数据负载,这应该避免。
最好是预先收集一些global (array) $prefix_meta_box_values
然后将其用于前端输出。
您还可以在上填充一些数组save_post
钩只需使用get_post_meta( $post_id, \'key\', \'value\' )
在admin UI中的post edit屏幕上的函数中,并使用将其添加到某个db字段中update_option(\'agents_data\')
. 这样你就可以打电话get_option(\'agents_data\');
并填充选择框。
Update:
// The updata agents option could look like this, asuming that you already added
// some data with an add_option call somewhere. Else you could just grap the old
// data, merge it with the new and update the post meta field.
// This was fastly written out of my head, so don\'t expect it to work without any fixing.
function my_agents_data()
{
$new_agents_data = get_post_meta( $GLOBALS[$post]->ID, \'key\', \'value\' );
$old_agents_data = get_option( \'agents_data\' );
$resulting_agents_data = array_merge( $old_agents_data, $new_agents_data );
update_option( \'agents_data\', $resulting_agents_data );
}
add_action( \'save_post\', \'my_agents_data\' );
这将允许您从get_option(\'agents_data\')
wp选项表中的选项字段。关键是,您应该避免元数据进入post元数据表。如何使permalink可用于搜索结果页/?s=一+二+确定到/搜索/一-二确定/感谢