如果您对下面的大量代码有任何批评,我将不胜感激。我要做的是查询一组自定义帖子,并根据自定义字段将它们返回到表中。它起作用了。。。正在生成表,返回正确的帖子,但在执行查询后,所有其他仪表板页面都为空。
//add menu option
add_action( \'admin_menu\', \'my_plugin_menu\' );
function my_plugin_menu() {
add_options_page( \'Limitless Options\', \'Limitless\', \'manage_options\', \'limitless\', \'my_plugin_options\' );
}
function my_plugin_options() {
if ( !current_user_can( \'manage_options\' ) ) {
wp_die( __( \'You do not have sufficient permissions to access this page.\' ) );
}
if( isset($_GET[\'set\']) ) {
//variables
$checkk = array();
$meta = NULL;
$date = NULL;
//validate
$start = ($_GET[\'start\'] != NULL ? $_GET[\'start\'] : false);
$end = ($_GET[\'end\'] != NULL ? $_GET[\'end\'] : false);
$question = ($_GET[\'question\'] != NULL ? $_GET[\'question\'] : false);
$answer = ($_GET[\'answer\'] != NULL ? $_GET[\'answer\'] : false);
$greutate_actuala = ($_GET[\'greutate_actuala\'] != NULL ? $_GET[\'greutate_actuala\'] : false);
$greutate_dorita = ($_GET[\'greutate_dorita\'] != NULL ? $_GET[\'greutate_dorita\'] : false);
$check = ($_GET[\'check\'] != NULL ? $_GET[\'check\'] : false);
$startEx = explode("-", $start);
$endEx = explode("-", $end);
if($greutate_actuala) {
$greutate_a = array(
\'key\' => \'greutate_actuala\',
\'value\' => $greutate_actuala,
);
}else{
$greutate_a = NULL;
}
if($greutate_dorita) {
$greutate_d = array(
\'key\' => \'greutate_dorita\',
\'value\' => $greutate_dorita,
);
}else{
$greutate_d = NULL;
}
if($check) {
$checkk = array(
\'key\' => \'check\',
\'value\' => 1,
);
}
if($question && $answer) {
$meta = array(
\'key\' => $question,
\'value\' => $answer,
);
}
if($question && !$answer) {
$meta = array(
\'key\' => $question,
);
}
if(!$question && $answer){
$meta = array(
\'value\' => $answer,
);
}
if($start && $end) {
echo "start and end";
$date = array(
\'after\' => array(
\'year\' => $startEx[0],
\'month\' => $startEx[1],
\'day\' => $startEx[2],
),
\'before\' => array(
\'year\' => $endEx[0],
\'month\' => $endEx[1],
\'day\' => $endEx[2],
),
\'inclusive\' => true,
);
}
if($start && !$end) {
echo "start not end";
$date = array(
\'year\' => $startEx[0],
\'month\' => $startEx[1],
\'day\' => $startEx[2],
);
}
$args = array(
\'post_type\' => \'quiz\',
\'meta_query\' => array(
$meta,
$greutate_a,
$greutate_d,
$checkk,
),
\'date_query\' => array(
$date
),
);
$loop = new WP_Query( $args );
echo \'<table border="1" class="table">
<tr>
<td>Nume</td>
<td>Email</td>
\';
for($i=1; $i<=10; $i++) {
echo \'<td \'.(($_GET[\'question\'] === \'question_\'.$i.\'\') ? \'class="active"\' : "").\'>Question \'.$i.\'</td>\';
}
echo \'<td \'.(($greutate_actuala) ? \'class="active"\' : "").\'>GA</td>
<td \'.(($greutate_dorita) ? \'class="active"\' : "").\'>GD</td>
<td \'.(($check) ? \'class="active"\' : "").\'>Check</td>
</tr>\';
while ( $loop->have_posts() ) : $loop->the_post();
echo \'<tr>\';
echo "<td>".get_post_meta(get_the_ID(), \'name\', true)."</td>";
echo "<td>".get_post_meta(get_the_ID(), \'email\', true)."</td>";
for($i=1; $i <= 10; $i++) {
echo "<td>".get_post_meta(get_the_ID(), \'question_\'.$i.\'\', true)."</td>";
}
echo "<td>".get_post_meta(get_the_ID(), \'greutate_actuala\', true)."</td>";
echo "<td>".get_post_meta(get_the_ID(), \'greutate_dorita\', true)."</td>";
echo "<td>".get_post_meta(get_the_ID(), \'check\', true)."</td>";
echo \'</tr>\';
$idArr[] = get_the_ID();
endwhile;
echo \'</table>\';
if(isset($_POST[\'csv\'])) {
csvDownload($idArr);
}
if(isset($_POST[\'dl-csv\'])) {
email_csv();
}
echo \'<form method="post" action="">
<input type="submit" name="csv" value="csv">
</form>
\';
if(isset($_POST[\'csv\'])) {
echo \'<form method="post" action="">
<p>CSV to: \'.get_option( \'admin_email\' ).\' Add more: <input type="email" name="email"> ex: [email protected], [email protected]</p>
<input type="submit" name="dl-csv" value="Send CSV">
</form>
\';
}
}