大家好,我是一个 WordPress 菜鸟,所以请多多包涵。因此,在 template.php 中,我需要meta_form()
根据一些条件更改函数的功能。这是它的样子:
原始代码:
function meta_form() {
global $wpdb;
$limit = (int) apply_filters( 'postmeta_form_limit', 30 );
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
if ( $keys )
natcasesort($keys);
?>
定制版:
function meta_form() {
global $wpdb;
if ( isset($_GET['post']) )
$post_id = (int) $_GET['post'];
elseif ( isset($_POST['post_ID']) )
$post_id = (int) $_POST['post_ID'];
else
$post_id = 0;
if ( $post_id ) {
$post_ = get_post($post_id);
}
if ($post_->post_type == 'video_photo' ){
$limit = (int) apply_filters( 'postmeta_form_limit', 30 );
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
where meta_key like 'tqmcf_%'
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
}else{
$limit = (int) apply_filters( 'postmeta_form_limit', 30 );
$keys = $wpdb->get_col( "
SELECT meta_key
FROM $wpdb->postmeta
GROUP BY meta_key
HAVING meta_key NOT LIKE '\_%'
ORDER BY meta_key
LIMIT $limit" );
}
if ( $keys )
natcasesort($keys);
?>
meta_form
覆盖函数的最佳方法是什么?我必须创建一个插件或其他东西吗?我似乎找不到一个干净的答案。(ps我没有编写此代码,我只是修复它的人)。