I'm making a website and want to display Events. Therefore I made a Custom Post Type called 'event'.
I'm querying events to show them in a page. The Events I made also have some custom fields like : 'Location', 'Day', 'Month', 'Year' and a category.
This is my code now :
<?php
$args = array(
'post_type' => 'event',
);
$events = new WP_Query( $args );
if( $events->have_posts() ) {
while( $events->have_posts() ) {
$events->the_post();
?>
<div class='event'>
<div class="event-date">
</div>
<div class="event-content">
<div class="event-title"><?php the_title() ?></div>
<div class="event-info">
<span>Location: </span>
<span>Category: </span>
</div>
</div>
</div>
<?php
}
} else {
echo 'No events!';
}
?>
Which only gives me the title. How can I display the custom fields and the category ?
I am fairly new to WordPress development, used to programming in .NET.
Thx for any help!
I'm making a website and want to display Events. Therefore I made a Custom Post Type called 'event'.
I'm querying events to show them in a page. The Events I made also have some custom fields like : 'Location', 'Day', 'Month', 'Year' and a category.
This is my code now :
<?php
$args = array(
'post_type' => 'event',
);
$events = new WP_Query( $args );
if( $events->have_posts() ) {
while( $events->have_posts() ) {
$events->the_post();
?>
<div class='event'>
<div class="event-date">
</div>
<div class="event-content">
<div class="event-title"><?php the_title() ?></div>
<div class="event-info">
<span>Location: </span>
<span>Category: </span>
</div>
</div>
</div>
<?php
}
} else {
echo 'No events!';
}
?>
Which only gives me the title. How can I display the custom fields and the category ?
I am fairly new to WordPress development, used to programming in .NET.
Thx for any help!
Share Improve this question asked Dec 22, 2016 at 9:55 Nanou PonetteNanou Ponette 1551 gold badge1 silver badge9 bronze badges1 Answer
Reset to default 8Custom fields are saved in the post_meta table. In your query you got the post title and post ID, so now you have to get post meta.
Use:
<?php
get_post_meta( get_the_ID(), '_location', true );
?>
same for the rest of your custom fields only '_location' will change according to field you are getting. Read more about post meta here
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745001545a4605524.html
评论列表(0条)