• Resolved goldmember

    (@goldmember)


    in the right sidebar of my page (https://www.diveneycue.com/wordpress/) i am using the PHP code widget with the following code:

    <br />
    <?php
    $my_query = new WP_Query('category=45&orderby=post_title&order=ASC&showposts=10');
    if ($my_query->have_posts()) {
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <?php the_title(); ?>
            <?php the_excerpt(); ?>
        <?php endwhile;
    }
    ?>

    what it should be doing is listing only those posts from my Events category (category ID = 45). but it seems to be including postings that are not in my Events category. also, it doesnt appear to be listing the stuff in alphebetical order, by title, as I though I had correctly written in the php arguments.

    please advise whats wrong. thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter goldmember

    (@goldmember)

    actually now i’m using the code below which seems to be doing the trick. however, i want it to sort the postings alphabetically by title (the dates are the titles) but it doesnt appear to be doing that.

    please advise how i make that happen??? thanks.

    <br />
    <?php $recent = new WP_Query("cat=45&orderby=name&order=ASC"); while($recent->have_posts()) : $recent->the_post();?>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>

    What do you mean by “the dates are the titles”?

    Thread Starter goldmember

    (@goldmember)

    i typed the dates in the title fields for the posts. for example: https://www.diveneycue.com/wordpress/events/31810-32110/

    so i’d like to sort the posts by title (and therefore by date). how do i make that happen???

    That’s going to be tough. 1) I believe that the MySQL engine will sort as a string which is not always the same as sorting numerically and 2) even if you could get a numeric sort it doesn’t work for dates unless you have those dates in the YYYYMMDD (ie. 20100211) format (which is quite convenient but rarely used). And you appear to have two dates separated by dashes as well, which will complicate things.

    I hate to say it but I think your approach is fundamentally wrong. You should be using the built in post date data if you want to sort by date.

    Thread Starter goldmember

    (@goldmember)

    ok. thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP Code widget how following arguments’ is closed to new replies.