- This topic is empty.
-
AuthorPosts
-
May 1, 2013 at 4:52 pm #44490
asiek
ParticipantI followed [this](http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/ “http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/”) tutorial. Everything looks fine except I wanted to add 2-3 of the latest events on the homepage, just not sure how to display 2 posts from a CPT etc…
Please Help…
May 1, 2013 at 6:04 pm #133773asiek
Participant@siouxfan45 Thanks, I will try it out :)
May 1, 2013 at 6:16 pm #133776asiek
ParticipantDidn’t work :/
May 1, 2013 at 7:05 pm #133787will_wallace85
MemberThat link isn’t loading for me, can you post your code for the loop and the register post type from your functions.php file? With those two pieces we should be able to help.
May 1, 2013 at 9:50 pm #133802asiek
ParticipantI have page.php , and loop-page.php
here is the loop-page.php content//
Register CPT//
[http://pastebin.com/MFBEPZVK](http://pastebin.com/MFBEPZVK “http://pastebin.com/MFBEPZVK”)Link to tutorial//
[http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/](http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/ “http://tatiyants.com/how-to-use-wordpress-custom-post-types-to-add-events-to-your-site/”)May 2, 2013 at 2:17 am #133815nigel123
MemberOkay, not sure how beneficial this is going to be but I’m going to try! Firstly, events are my worst favourite CPT to create, if you can use a (reputable) plugin I would. Reason: I dislike dates – past dates, events still showing up after even has passed, etc.
Okay mini vent over! This is something similar to what I have made. Some notes I would change is on the CPT is entering the DATE as YYYY-MM-DD rather than MM/DD/YYYY – it just makes it work better in the meta_query.
Also I’m no way a WordPress aficionado or knowledged. This is just somethings I came across and combined into one. I’m not even sure if it is usuable, but it’s a start and somebody might be able to clean it up/improve it for both of us!
// Required
global $post;// Some variables!
$event_s_date = get_post_meta( $post->ID, ‘event_date’, true ); // Get your start date from the CPT post
$current_date = date( “Y-m-d”, mktime(0,0,0,date(“m”),date(“d”),date(“Y”)) ); // Get todays date// Conversions
$event_s_date = date(“Y-m-d”, strtotime($event_s_date)); // Turn the CPT start date PHP readable/comparable data// LOOP TIME YAY!
$args = array(
‘post_type’ => ‘event’,
‘post_status’ => ‘publish’,
‘numberposts’ => 2,
‘meta_query’=> array(
array(
‘key’ => ‘event_date’,
‘compare’ => ‘>’,
‘value’ => $current_date,
‘type’ => ‘DATE’,
)
),
‘meta_key’ => ‘event_date’,
‘orderby’ => ‘meta_value’,
‘order’ => ‘ASC’
);$event_posts = get_posts($args);
// If there are events to show
if($event_posts) {foreach($event_posts as $post) {
setup_postdata($post);
// Enter the stuff for your post (Title, dates, times, etc.)
}// If there are no events to show
} else {// Enter stuff if there are no events
}
?> -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.