Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在多个选项卡中使用相同的功能_Php_Wordpress - Fatal编程技术网

Php 在多个选项卡中使用相同的功能

Php 在多个选项卡中使用相同的功能,php,wordpress,Php,Wordpress,我有一个php脚本,可以呈现几个选项卡 在每个选项卡中都有一个代码,该代码在几个选项卡中重复,这使得更新过程变得困难 示例: <div id="1" class="tabcontent"> <?php if (!empty( $_POST['newtags'] ) ) { wp_set_post_tags( $post->ID, $_POST['newtags'], true ); } ?> </div> <div id="2" class="

我有一个php脚本,可以呈现几个选项卡

在每个选项卡中都有一个代码,该代码在几个选项卡中重复,这使得更新过程变得困难

示例:

<div id="1" class="tabcontent">
<?php 
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>

<div id="2" class="tabcontent">
<?php 
if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
}?>
</div>

<div id="3" class="tabcontent">
    <?php 
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>
function set_newtags() {
 if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
  }
}

function set_newmeta() {
 if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
  }
}
<div id="1" class="tabcontent">
<?php set_newtags() ?>
</div>

<div id="2" class="tabcontent">
<?php set_newmeta() ?>
</div>

<div id="3" class="tabcontent">
<?php set_newtags() ?>
</div>
(这样,我只需要更新一个函数,而不是在多个选项卡中更新多个代码副本)

和than,在各自的选项卡中调用它们,如下所示:

<div id="1" class="tabcontent">
<?php 
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>

<div id="2" class="tabcontent">
<?php 
if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
}?>
</div>

<div id="3" class="tabcontent">
    <?php 
if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
} ?>
</div>
function set_newtags() {
 if (!empty( $_POST['newtags'] ) ) {
wp_set_post_tags( $post->ID, $_POST['newtags'], true );
  }
}

function set_newmeta() {
 if (!empty( $_POST['h2'])){ // if the input field is not empty
update_post_meta($post->ID, 'description', $concatenated_description, $description_field );
  }
}
<div id="1" class="tabcontent">
<?php set_newtags() ?>
</div>

<div id="2" class="tabcontent">
<?php set_newmeta() ?>
</div>

<div id="3" class="tabcontent">
<?php set_newtags() ?>
</div>

问题?这不起作用


“我做错了什么?”

如果在这些函数中使用
return
,比如
return update\u post...