douju8782
2015-10-09 11:23
浏览 120
已采纳

PHP使用$ out回显自定义字段

i am using the Favorites plugin in Wordpress to save posts. I'm trying to adjust the way the information is displayed though. All the styling etc works below and my divs are being included, however i am struggling to pull information through to fill the divs. Fore example, i am trying to pull the excerpt in to the p.details but it is just throwing out an empty result, with no errors. Similarly, i am trying to pull through an acf custom field of 'bath' into p.bath but that is also empty. Any suggestions? Thanks in advance.

if ( is_multisite() ) switch_to_blog($this->site_id);

    $out = '<ul class="property-list" data-userid="' . $this->user_id . '" data-links="true" data-siteid="' . $this->site_id . '" ';
    $out .= ( $include_button ) ? 'data-includebuttons="true"' : 'data-includebuttons="false"';
    $out .= ( $this->links ) ? ' data-includelinks="true"' : ' data-includelinks="false"';
    $out .= ' data-nofavoritestext="' . $no_favorites . '"';
    $out .= ' data-posttype="' . $post_types . '"';
    $out .= '>';
    foreach ( $favorites as $key => $favorite ){
        $out .= '<li data-postid="' . $favorite . '">';
        $out .= '<div class="third-1">';
        $out .= '<a class="property-thumb" href="' . get_permalink($favorite) . '">';
        $out .= '</a>';
        $out .= '</div>';
        $out .= '<div class="third-2">';
        if ( $this->links ) $out .= '<h3 class="name"><a href="' . get_permalink($favorite) . '">';
        $out .= get_the_title($favorite);
        if ( $this->links ) $out .= '</a></h3>';
        if ( $this->links ) $out .= '<h4 class="price">';
        $out .= '£' . '300';
        if ( $this->links ) $out .= '</h4>';
        if ( $this->links ) $out .= '<p class="details">';
        $out .= the_excerpt();
        if ( $this->links ) $out .= '</p>';
        if ( $this->links ) $out .= '<p class="bed">';
        $out .= '1';
        if ( $this->links ) $out .= '</p>';
        if ( $this->links ) $out .= '<p class="bath">';
        $out .= '1';
        if ( $this->links ) $out .= '</p>';
        if ( $this->links ) $out .= '<a class="full-details" href="' . get_permalink($favorite) . '">';
        $out .= 'Full details';
        if ( $this->links ) $out .= '</a>';
        if ( $this->links ) $out .= '<a class="book-viewing" href="' . get_permalink($favorite) . '">';
        $out .= 'Book Viewing';
        if ( $this->links ) $out .= '</a>';
        $out .= '</div>';
        $out .= '</li>';
    }
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyue8640 2015-10-09 13:19
    已采纳

    Change the_excerpt(); to get_the_excerpt(); and it should work.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题