wp-widgets issue on the front end

25 views
Skip to first unread message

Andre Dublin

unread,
Jun 9, 2011, 1:34:33 PM6/9/11
to event...@googlegroups.com
Heres a new one.

I see in your wp-widgets.php file of the plugin that allows me to display events in a widget enable area

What I am trying to do is limit the number of posts shown, here is my code.

<php

$temp = $wp_query;
$wp_query = null;
$args = array(
'post_type' => 'ep_event',
'orderby' => 'meta_value',
'meta_key' => '_ep_start',
'order' => 'DESC',
'posts_per_page' => 5
);
$wp_query = new WP_Query( $args );

echo "<ul>";

if ( have_posts() ) {
         while( $wp_query->have_posts() ) {
                   $wp_query->the_post();
?>

<li>
<a href="<?php echo get_permalink() ?>"><?php echo get_the_post_thumbnail($post->ID, array("40","40"), array("class"=>"alignleft")) ?></a>
<a href="<?php echo get_permalink() ?>"><h4><?php echo $post->post_title ?></h4></a>
<?php ep_start_date(); ?> <?php ep_start_time(); ?>
<p><?php echo get_the_excerpt() ?></p>
</li>

<?
          }
}

$wp_query = null;
$wp_query = $temp; //reset back to original query
echo "</ul>";

I modified some of the output for our site, which I am sure is not the problem.  In my $args array I have the condition of posts_per_page set to 5, but the widget is still displaying all published events??

Your thoughts?

Kunal Bhalla

unread,
Jun 9, 2011, 1:40:16 PM6/9/11
to event...@googlegroups.com
Nothing I can think of at the moment. Passing 5 should be over-riding
the default query. Does calling $wp_posts->the_post() override the
global $post too? And why do you need an if—at the very least it
should be outside the ul tags?

Kunal

Andre Dublin

unread,
Jun 9, 2011, 1:57:07 PM6/9/11
to event...@googlegroups.com
The if statement is just a initial check it see if we have any posts to post.

Putting it outside or inside the ul tags doesn't affect anything.

What I am wondering if there is a function in the eventpress controller or model that is affecting this?

For the time being I'll try some different query methods.


Kunal Bhalla

unread,
Jun 9, 2011, 2:01:04 PM6/9/11
to event...@googlegroups.com
The if statement won't have an effect at all. If
$wp_posts->have_posts() evaluates to false, the while loop won't run
at all anyways.

You could have a look at the filters, but nothing within EP should be
over-riding a query.


Kunal

Andre Dublin

unread,
Jun 10, 2011, 12:06:51 PM6/10/11
to event...@googlegroups.com
So here is my solution for now.  It's hacky but works

$temp = $wp_query;
$wp_query = null;
$args = array(
'post_type' => 'ep_event',
'orderby' => 'meta_value',
'meta_key' => '_ep_start',
'order' => 'DESC'
);
$wp_query = new WP_Query( $args );

$i = 0;
echo "<ul>";
while( $wp_query->have_posts() ) {
$i++;
$wp_query->the_post();
?>
<li>
<a href="<?= get_permalink() ?>"><?= get_the_post_thumbnail($post->ID, array("40","40"), array("class"=>"alignleft")) ?></a>
<a href="<?= get_permalink() ?>"><h4><?= $post->post_title ?></h4></a>
<?php ep_start_date(); ?> <?php ep_start_time(); ?>
<p><?= get_the_excerpt() ?></p>
</li>
<?
if ( $i >= 5 ) {
break;
}
}
echo "</ul>";
$wp_query = null;
$wp_query = $temp; // reset back to original query


I just set up an iterator and break out of the loop at 5 posts.  I tried many other methods, but i kept getting all the posts...

Kunal Bhalla

unread,
Jun 10, 2011, 12:21:04 PM6/10/11
to event...@googlegroups.com
Strange. I'll be kind of rebuilding ep from scratch in a month or
so—sharpening my developer's axe right now. Will check it properly
then.
Kunal

Andre Dublin

unread,
Jun 10, 2011, 12:35:03 PM6/10/11
to event...@googlegroups.com
I'm gonna change this iterator loop to a filter so it will be less obtrusive to the code.  I'll be looking forward to the update.

Andre Dublin

unread,
Jun 10, 2011, 12:46:52 PM6/10/11
to event...@googlegroups.com
Your code is great, just make it less abstracted.  I would even suggest combining bpcp and eventpress.

Kunal Bhalla

unread,
Jun 10, 2011, 12:50:57 PM6/10/11
to event...@googlegroups.com
My main aim is to introduce unit and integration testing. A rather
major of source of bugs and headaches have been regressions I
introduced because i didn't have the patience to test code across
multiple installs of plain wordpress, and buddypress and hand-testing
everything else. (And that is something I will never have—the tests
have to be completely automated or I won't do them).

Plus MVC doesn't really sit that well within a WP plugin; so I plan to
re-structure the code a bit; there's also some repetition that
happened because I didn't pay attention (particularly in the
registration area).

And the UI, of course—well the less I say about it the better.

Kunal

Andre Dublin

unread,
Jun 10, 2011, 1:43:50 PM6/10/11
to event...@googlegroups.com
Honestly I find the MVC pattern you used to be great finding what I need to modify.  As for the jquery ui stuff, I find that the slider is confusing for users when it comes to selecting a hour the event starts.  I would recommend an select input that will provide a dropdown.  From what we've learned with our users they don't get the slider thing, even though I think its awesome.

Kunal Bhalla

unread,
Jun 10, 2011, 1:49:12 PM6/10/11
to event...@googlegroups.com
Yeah — the MVC worked out great that way; but at a lot of places
(particularly in the views section) it felt really forced (what goes
into a WP-Tag? Where do I put the registration template? etc.). I'm
thinking of moving to a more component based version: for example, a
separate class for the different views, (such as the ep-calendar.php
file): something that fits in better with how wordpress works—a mix
between what I have right now and the buddypress plugin structure. Any
suggestions on an ideal plugin structure would be great.

In terms of the date/time ui I've been directly using a jquery plugin;
I've seen various variations on the time selection—some have been
really good too, but didn't seem to be stable. Maybe I'll try and roll
my own this time.

Custom form creation is one of the really major areas that needs work
(I exposed the 'regex' portion to allow for more flexibility, but
quite a few people commented on this bit), etc.

Kunal

Reply all
Reply to author
Forward
0 new messages