echo custom field in a table
-
I have a custom post type called “Console”. One of the fields is called “model”. “Model” is a custom defined list where these are some of my options: Xbox One X, Xbox One S, PS4 …etc.
I want to display all of these “models” in a table. This is what I got:
function buying_report() { $models = array( 'post_type' => 'console', 'post_status' => 'publish', ); $query = new WP_Query($models); if ($query->have_posts()) { echo "<table border=\"1\" align=\"center\">"; echo "<tr><th>Model</th>"; echo "<th>Price</th></tr>"; while ($query->have_posts()) { $query->the_post(); echo "<tr><td>"; echo get_field( get_the_id(), 'model', true); echo "</td><td>"; echo "</td></tr>"; } } echo "</table>"; }
This works but is giving me a lot of duplicate models. Am I doing it correctly?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘echo custom field in a table’ is closed to new replies.