Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • In the meantime I found a great article after 2 hours of googling

    Thanks, 3stripe. This article proved exactly what I needed. I wanted to be able to sort my posts, not categories. Eventually I came up with the idea to add a custom field named ‘volgnummer’ and sort the posts by the value of that field.

    My query now looks like this:

    $pageposts = $wpdb->get_results("
    SELECT
    wposts.*
    FROM
    $wpdb->posts wposts,
    $wpdb->postmeta wpostmeta
    WHERE
    wposts.ID = wpostmeta.post_id
    AND
    wpostmeta.meta_key = 'volgnummer'
    ORDER BY
    wpostmeta.meta_value ASC", OBJECT);
    if ($pageposts) : foreach ($pageposts as $post): setup_postdata($post);
    // Yada yada yada
    endforeach;
    endif

    Hopefully this is of any use.

    Thread Starter minus3

    (@minus3)

    See if this thread helps: […]

    Thanks, moshu. To put it in a Dutch way, yesterday I couldn’t see the trees through the forest no longer – I found too many different solutions and wasn’t sure which method would be the correct one, but Kafkaesqui’s code was very easy for me to implement and modify.

    For those who are interested what I changed, almost nothing.


    foreach($posts as $post) :
    the_post();
    $category = get_the_category();
    if($current_cat == $category[0]->cat_ID) :
    /*
    display post here....
    */
    break; // break out of this loop after having displayed the first post
    endif; // end 'if post in correct category'
    endforeach; // end post loop

    And since the posts are ordered chronologically by default, that break was all I had to add to make it work the way I want.

    And ryanfitzer, thanks for the reply anyway.

    Maarten

Viewing 2 replies - 1 through 2 (of 2 total)