Support

Home Forums Event Espresso Premium Get_posts -> how to get events listed by date?

Get_posts -> how to get events listed by date?

Posted: July 1, 2014 at 4:30 pm

Viewing 2 reply threads


Alessio

July 1, 2014 at 4:30 pm

Hello, I am trying to implement a custom code like this:

<code>&lt;php $args = array(
'posts_per_page'   =&gt; -1,
'offset'           =&gt; 0,
'category'         =&gt; '',
'orderby'          =&gt; 'post_date',
'order'            =&gt; 'DESC',
'include'          =&gt; '',
'exclude'          =&gt; '',
'meta_key'         =&gt; '',
'meta_value'       =&gt; '',
'post_type'        =&gt; 'espresso_events',
'post_status'      =&gt; 'publish',
'suppress_filters' =&gt; false ); 

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?&gt;
&lt;li&gt;
&lt;?php 

$datetimes = $post-&gt;EE_Event-&gt;datetimes_ordered();

foreach($datetimes as $datetime) {
 $startDate = $datetime -&gt; _DTT_EVT_start;
}
?&gt;
&lt;a href=&quot;&lt;?php the_permalink(); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt; 
&lt;?php echo $startDate;?&gt;
&lt;/li&gt;
&lt;?php endforeach; ?&gt;
</code>

It doesn’t seem to work. I mean, I can list events. But there is no way to actually:

SORT events by date
Show events’ dates

Can you confirm this? Tryin to use my code it throws a php error

Fatal error: Cannot access protected property EE_Datetime::$_DTT_EVT_start

I read your /classes/EE_Datetime.html#method_datetimes_ordered page and it says that property is protected. So…how can I use it to show a single event’s date using custom wordpress queries?

Moreover, your documentation is incomplete, here -> https://eventespresso.com/wiki/ee4-custom-post-types/ you forgot to say that ”
‘suppress_filters’ => false” is MANDATORY otherwise the EE_Event object won’t work 😉

  • This topic was modified 10 years, 4 months ago by Alessio.
  • This topic was modified 4 years, 8 months ago by Seth Shoultes.


Alessio

July 1, 2014 at 4:33 pm

Sorry, the code I sent was not easy to read. Trying again…

<pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”><php $args = array(
‘posts_per_page’ => -1,
‘offset’ => 0,
‘category’ => ”,
‘orderby’ => ‘post_date’,
‘order’ => ‘DESC’,
‘include’ => ”,
‘exclude’ => ”,
‘meta_key’ => ”,
‘meta_value’ => ”,
‘post_type’ => ‘espresso_events’,
‘post_status’ => ‘publish’,
‘suppress_filters’ => false );

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>

<?php

$datetimes = $post->EE_Event->datetimes_ordered();

foreach($datetimes as $datetime) {
$startDate = $datetime -> _DTT_EVT_start;
}
?>
“><?php the_title(); ?>
<?php echo $startDate;?>

<?php endforeach; ?>


Dean

July 2, 2014 at 2:23 am

Hi,

Sorry about the code syntax highlighter, it is temprmental. PAstebin is useful for code blocks.

In answer, check out this code snippet written by Josh, https://gist.github.com/joshfeck/e3c9540cd4ccc734e755

It provides a way to query the EE events where they can also be sorted by things like event date.

Viewing 2 reply threads

The support post ‘Get_posts -> how to get events listed by date?’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso