第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何通過(guò)查詢?cè)谇岸孙@示CPT元

如何通過(guò)查詢?cè)谇岸孙@示CPT元

PHP
慕妹3242003 2021-04-26 13:12:56
我在網(wǎng)站上使用兩種自定義帖子類型:Team和League。我正在為CPT聯(lián)賽創(chuàng)建一個(gè)頁(yè)面模板,該模板將顯示團(tuán)隊(duì)所有“團(tuán)隊(duì)”帖子中的元數(shù)據(jù),其元值與聯(lián)賽職位類型的名稱相匹配。該查詢將在CPT“團(tuán)隊(duì)”中查找元值“ team_league”?!?team_league”中的值將與“ league”類型的職位ID之一匹配。然后,我想在“聯(lián)賽”頁(yè)面上打印每個(gè)匹配的“團(tuán)隊(duì)”以及團(tuán)隊(duì)帖子中的一些元數(shù)據(jù)。如果僅打印一個(gè)簡(jiǎn)單的查詢名稱,而該名稱僅包含查詢中找到的帖子名稱,則可以成功完成此操作。下面的示例成功查詢并打印每個(gè)“團(tuán)隊(duì)”的職位名稱,并帶有與“聯(lián)賽”標(biāo)題匹配的元值。但是,我需要更復(fù)雜的東西。我想從“團(tuán)隊(duì)”帖子中提取元數(shù)據(jù),并打印一個(gè)包含“團(tuán)隊(duì)” CPT名稱的表格。有效的簡(jiǎn)化查詢:if ( $the_query->have_posts() ) {  echo '<ul>';  while ( $the_query->have_posts() ) {    $the_query->the_post();    echo '<li>' . get_the_title() . '</li>';  }  echo '</ul>';所需查詢,當(dāng)前不起作用:<?php/*Template Name: League LayoutTemplate Post Type: league*/$leaguename = get_the_ID();$args = array(    'meta_key' => 'team_league',    'meta_value' => $leaguename,    'post_type' => 'team',    'post_status' => 'any',    'posts_per_page' => -1);$the_query = new WP_Query( $args );// The Loopif ( $the_query->have_posts() ) {  while ( $the_query->have_posts() ) {    $the_query->the_post();    //Get the team data    $post_status = get_post_status();    $team_name = get_the_title();    $captain_id = get_post_meta(get_the_ID(), 'captain_user_id', true);    $team_captain = get_user_by( 'ID', $captain_id );    $team_league = get_post(get_post_meta(get_the_ID(), 'team_league', true));    $team_players = get_post_meta(get_the_ID(), 'team_players_emails', true);    $team_paid = get_post_meta(get_the_ID(), 'current_paid_amount', true);    $team_fee = get_post_meta(get_the_ID(), 'payment_product_price', true);    $team_balance = round( $team_fee - $team_paid , 2);   echo '<p>Team Captain: <b>' . $team_captain->first_name . ' ' . $team_captain->last_name; . '</b></p>';   echo '<p>Team Balance: <b>$' . $team_balance; . '</b></p>';   echo '<table>';   echo '<tr>';   echo '<th>Team Roster</th>';   echo '</tr>';
查看完整描述

2 回答

?
哆啦的時(shí)光機(jī)

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊

為您的查詢Args。嘗試這樣的事情:


$args = array (

    'post_type' => 'team',

    'posts_per_page' => -1,

    'meta_query'  => array(

       'relation' => 'AND',

           array(

            'key'     => 'team_league',

            'value'   => $leaguename,

           ),

    ),

);

我認(rèn)為沒(méi)有用'post_status' => 'any'。這也使用正確的元查詢格式。


查看完整回答
反對(duì) 回復(fù) 2021-05-07
?
人到中年有點(diǎn)甜

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊

作為參考,以下解決方案可以實(shí)現(xiàn)我的目標(biāo)。主要更改是args,我必須在其中包含CPT的自定義帖子狀態(tài):


$leagueid = get_the_ID();


$args = array(

  'post_type'      => 'team',

  'posts_per_page' => - 1,

  'post_status' => array( 'mssl-completed', 'mssl-pending', 'publish' ),

  'meta_query' => array(

     array(

        'key'   => 'team_league',

        'value' => "$leagueid",

     ),

   ),

 );

從這里,我能夠?qū)膒ost meta提取的信息寫到我的自定義頁(yè)面模板中。


查看完整回答
反對(duì) 回復(fù) 2021-05-07
  • 2 回答
  • 0 關(guān)注
  • 172 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)