Skip to content

Instantly share code, notes, and snippets.

@wpmu-authors
Created April 28, 2022 17:19
Show Gist options
  • Save wpmu-authors/908bc43d394682bbd195116538e162d7 to your computer and use it in GitHub Desktop.
Save wpmu-authors/908bc43d394682bbd195116538e162d7 to your computer and use it in GitHub Desktop.
add_filter( 'the_content', 'show_diary_details' );
function show_diary_details( $content ) {
$diary = '';
if( has_category( 'workout' ) ) {
$diary = '<table>
<tr>
<th>Activity</th>
<th>Duration</th>
<th>Distance</th>
<th>Calories</th>
<th>Link</th>
</tr>
<tr>
<td>' . get_field( 'type' ) . '</td>
<td>' . get_field( 'duration' ) . ' min</td>
<td>' . get_field( 'distance' ) . ' km</td>
<td>' . get_field( 'calories' ) . ' kcal</td>
<td><a href="' . get_field( 'link' ) . '">link</a></td>
</tr>
</table>';
}
if( has_category( 'meal' ) ) {
$diary = '<table>
<tr>
<th>Calories</th>
<th>Fat</th>
<th>Protein</th>
<th>Carbohydrates</th>
<th>Cholesterol</th>
</tr>
<tr>
<td>' . get_field( 'calories' ) . ' kcal</td>
<td>' . get_field( 'fat' ) . ' g</td>
<td>' . get_field( 'protein' ) . ' g</td>
<td>' . get_field( 'carbohydrates' ) . ' g</td>
<td>' . get_field( 'cholesterol' ) . ' mg</td>
</tr>
</table>';
}
if( has_category( 'sleep' ) ) {
$diary = '<table>
<tr>
<th>Calories</th>
<th>Fat</th>
<th>Protein</th>
<th>Carbohydrates</th>
<th>Cholesterol</th>
</tr>
<tr>
<td>' . get_field( 'start' ) . '</td>
<td>' . get_field( 'end' ) . '</td>
</tr>
</table>';
}
return $content . $diary;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment