0

次のコードがあり、fact-sheet というカスタム投稿タイプから 3 つのものを表示する必要があります。

  1. タイトル
  2. 要約 (fact_sheet_summary)
  3. ファイルのアップロード URL (fact_sheet_pdf_link)

最初の 2 つを機能させることはできますが、3 つ目の方法はわかりません。基本的に私の出力は...

The Title The Summary paragraph Click here to download as PDF

これらの投稿タイプの結果をすべて一覧表示するためにクエリを実行する方法はありますか? 私が以下に持っているものよりも、これを行うためのより良い方法はありますか? 主な問題は、アップロードされたファイルの URL を取得できないことです。

<?php

$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'fact-sheet',
'order' => 'ASC',
));

if($posts)
{


foreach($posts as $post)
{
    echo '<span class="fact-sheet-title">' . get_the_title($post->ID) . '</span><br />';
    echo '<p><span class="fact-sheet-summary">' . the_field('fact_sheet_summary') . '</span></p>';
}
}

?>
4

2 に答える 2

1

これを試すことができますか?WP Codex のマニュアルからわずかに変更されています (それほどではありません)。

<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();    

 $args = array(
   'post_type' => 'attachment',
   'post_mime_type' => array('application/pdf'),
   'numberposts' => -1,
   'post_status' => null,
   'post_parent' => $post->ID
  );

  $attachments = get_posts( $args );
     if ( $attachments ) {
        foreach ( $attachments as $attachment ) {
           echo '<li>';
           the_attachment_link( $attachment->ID, true );
           echo '<p>';
           echo apply_filters( 'the_title', $attachment->post_title );
           echo '</p></li>';
          }
     }

 endwhile; endif; ?>
</ul>

それが機能する場合は、カスタム フィールドを追加して、実際のサンプルを必要に応じて変更することをお勧めします。ちょうど私の考え:-)

于 2014-02-24T21:52:19.890 に答える