admin管理员组文章数量:1428664
I used this code to display content from my custom fields only where post category id is 5, but all data from the custom fields show above the table in a straight line like a paragraph.
<?php
$post = $wp_query->post; if ( in_category('5') ) {
echo "<table><tr><td> ".the_field('song_title')."</td></td>
<tr><td>
<b>Artist: </b> ".the_field('artist')."</td></tr>
<tr><td>
<b >Song Title:</b> ".the_field('song_title')."</td></tr>
<tr><td>
<b>Song Lenght:</b> ".the_field('song_lenght')."</td></tr></table>
";
} ?>
I used this code to display content from my custom fields only where post category id is 5, but all data from the custom fields show above the table in a straight line like a paragraph.
<?php
$post = $wp_query->post; if ( in_category('5') ) {
echo "<table><tr><td> ".the_field('song_title')."</td></td>
<tr><td>
<b>Artist: </b> ".the_field('artist')."</td></tr>
<tr><td>
<b >Song Title:</b> ".the_field('song_title')."</td></tr>
<tr><td>
<b>Song Lenght:</b> ".the_field('song_lenght')."</td></tr></table>
";
} ?>
Share
Improve this question
edited May 2, 2019 at 15:17
Welcher
3,6481 gold badge20 silver badges24 bronze badges
asked May 2, 2019 at 14:55
PrezidoPrezido
112 bronze badges
2
|
1 Answer
Reset to default 3Welcome to this community Prezido. the_field()
function has echo in it. There is no problem with in_category()
function. You need to use get_field()
function when you echo the values of fields.
I've updated your code. This version should work as expected.
<?php
$post = $wp_query->post;
if ( in_category( '5' ) ) {
echo '<table>
<tr><td> ' . get_field( 'song_title' ) . '</td></tr>
<tr><td><b>Artist: </b> ' . get_field( 'artist' ) . '</td></tr>
<tr><td><b >Song Title:</b> ' . get_field( 'song_title' ) . '</td></tr>
<tr><td><b>Song Lenght:</b> ' . get_field( 'song_lenght' ) . '</td></tr>
</table>
'; }
本文标签: postsHaving Issues with incategoryneed help
版权声明:本文标题:posts - Having Issues with in_category , need help 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745531400a2662077.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<tr>
is not closed in the first line, you closetd
tag twice instead oftr
– anton Commented May 2, 2019 at 15:05