Home › Forums › Calendar Products › Events Calendar PRO › Creating custom WP queries
- This topic has 4 replies, 4 voices, and was last updated 9 years, 1 month ago by
Chris Titley.
-
AuthorPosts
-
March 8, 2017 at 12:07 pm #1251291
Chris Titley
ParticipantHi there, we need to create various bespoke calendar pages for a couple of sites we are building.
I’ve read the following – https://theeventscalendar.com/knowledgebase/using-tribe_get_events/ – and broadly understand it but am not sure of where this code sits in the markup for the whole page.
My current page query is show below. It’s a hatchet job and works, but doesn’t give me the control over all of the args like your code does. What *should* may code be for the whole page please?
<?php /* Template Name: Page Event */ ?>
<?php get_header(); ?>
<div class=”container”>
<div class=”row”>
<main class=”col-sm-8 main-content”>
<?php
$args = array(
‘post_status’=>’publish’,
‘post_type’=> ‘tribe_events’,
‘posts_per_page’=>20,
);
$get_posts = null;
$get_posts = new WP_Query();
$get_posts->query($args);
if($get_posts->have_posts()) : while($get_posts->have_posts()) : $get_posts->the_post(); ?>
“><?php the_title(); ?>
<br />
<?php if (tribe_get_start_date() !== tribe_get_end_date() ) { ?>
<?php echo tribe_get_start_date(); ?> – <?php echo tribe_get_end_date(); ?>
<?php } else { ?>
<?php echo tribe_get_start_date(); ?>
<?php } ?>
<?php the_excerpt(); ?>
<?php
endwhile;
endif;
wp_reset_postdata();
?>
</main>
<aside class=”col-sm-4 sidebar-content”>
</aside>
</div>
</div>
<?php get_footer(); ?>March 8, 2017 at 1:27 pm #1251343George
ParticipantHi there,
We are unfortunately not able to provide any assistance with coding, or with modifying the appearance or behavior of our plugins.
You’ll have to take the reins on writing your queries, implementing them, troubleshooting them, etc. Hopefully our guides like the tribe_get_events() guide help but these are just meant as starting places.
⚠️ Please read more about these policies here before responding: https://theeventscalendar.com/knowledgebase/what-support-is-provided-for-license-holders/
— George
March 8, 2017 at 1:34 pm #1251350George
ParticipantNow, while everything I wrote above is true, and you will have to take the reins on these questions/issues, I wanted to at least try and offer some general advice. 🙂
First, you linked to the tribe_get_events() guide, but your code shows that you’re not using tribe_get_events(). You’re using WP_Query.
If you want to use tribe_get_events(), then just use tribe_get_events() — no need to try and work with WP_Query.
Next, some of your code is a bit complicated and doesn’t need to be. Take this block of code of yours, for example:
$args = array(
‘post_status’=>’publish’,
‘post_type’=> ‘tribe_events’,
‘posts_per_page’=>20,
);
$get_posts = null;
$get_posts = new WP_Query();
$get_posts->query($args);
You could just rewrite that as this:
$get_posts = new WP_Query( array(
‘post_status’ => ’publish’,
‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => 20,
));
Thirdly here is a quick example of just using tribe_get_events() directly, which might work better for you. Try this:
$tribe_events = tribe_get_events( array(
'eventDisplay' => 'custom',
'post_status' => 'publish',
'posts_per_page' => 20
) );if ( ! empty( $tribe_events ) ) {
foreach ( $tribe_events as $event ) {
// This will display all of the available event data.
print_r( $event );// Echo the title of the event, for example.
echo $event->post_title;
}
}
I hope this helps!
GeorgeMarch 30, 2017 at 9:35 am #1262037Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Creating custom WP queries’ is closed to new replies.
