Yes, there are problems in your code. I’d like to recommend you to code on WordPress by opening relevant Codex pages for reference that, you are not mistaking.
First of all, in WP_Query()
you used 'category_name' => 'Featured Events'
. But according to codex, you can’t use Category name here, you have to use Category Slug, and a Category slug cannot contain a space within, they have to be connected with an underscore. (Reference)
At second, in get_post_meta()
your key is not right. Because a key cannot contain spaces within. You have to connect separate strings with underscore, like start_time
(not Start Time). I guess the keys are working where you coded with a single string like Date
. (Reference)
And lastly, at the end of each query, you used wp_reset_query();
to reset the query. But according to Codex, for WP_Query() the reset query code is not wp_reset_query();
, but wp_reset_postdata()
. (Reference)
That’s all.
ADDITIONAL
In one of my project I used many custom fields. So I made two reusable functions for using in all-over my project. Just paste the following in your funcitons.php
within <?php
and ?>
.
/**
* REUSABLE POST_META FUNCTION
*/
function has_custom_field( $fieldName="" ) {
global $post;
$fetchedCustomField = get_post_meta($post->ID, $fieldName, true);
$CFchecker = ($fetchedCustomField == '') ? '0' : '1';
return (bool) $CFchecker;
}
function custom_field( $fieldName="" ) {
global $post;
$fetchedCustomField = get_post_meta($post->ID, $fieldName, true);
return $fetchedCustomField;
}
And use them like:
<?php if(has_custom_field('date')) { echo custom_field('date'); } else { echo 'no date'; } ?>
And one additional tips: whenever you are coding on WordPress always use the WP_DEBUG
to 'true'
in wp-config.php
. And don’t forget to set it to 'false'
again after the completion of the development. (Reference)
Good luck!
EDIT
To specify Custom Field, just under post/page Add the custom field like this:
If you custom field is defined like the image, then the get_post_meta()
would be:
<?php echo get_post_meta($post->ID, 'start_date', true); ?>
But for using custom field, I love to use Advanced Custom Fields plugin.