• Hi,

    I’m trying to display a list of post using a custom query string, but i cannot show the paging links. This is my code:

    if ($_GET['paged'])
    {
        $offset = (get_query_var('paged')) ? get_query_var('paged') : 1;
    }
    else
    {
        $offset = 0;
    }
    $posts_x_page = get_option('posts_per_page');
    $args = array(
    	'post_type' => 'post',
            'meta_key' => 'artist',
            'meta_value' => '1',
            'numberposts' => $posts_x_page,
            'offset' => $offset,
            'post_status' => 'publish'
    	);
    $pageposts = get_posts($args);
    
    ?>
        <table class="list_ads" border="0" cellpadding="0" cellspacing="0">
    
        <?php if ($pageposts): ?>
            <?php foreach ($pageposts as $post): ?>
                <?php setup_postdata($post); ?>
                   Posts code
            <?php endforeach; ?>
        </table>
        <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    	<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
        </div>
        <?php endif; ?>

    Thanks all!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    You’re using get_posts to directly retrieve the posts. That won’t work with next_posts and previous_posts and such, because they rely on the main query in $wp_query.

    There’s no easy fix. Don’t use those functions or don’t use get_posts. Your choice.

    Thread Starter grankan

    (@grankan)

    And if I use a custom query like this:
    $querystr =”
    SELECT $wpdb->posts.* FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
    WHERE $wpdb->posts.post_status = ‘publish’
    AND $wpdb->postmeta.meta_key = ‘isla’
    AND $wpdb->postmeta.meta_value = ‘1’
    AND $wpdb->posts.post_type = ‘post’
    ORDER BY $wpdb->posts.post_date DESC”;
    $pageposts = $wpdb->get_results($querystr, OBJECT);

    Can i use a next_posts and previous_posts functions??

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, because again, you’re not using the wp_query object or the normal query system.

    You’d have to use some filters and such and modify the query directly. Which is tricky.

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

The topic ‘No show paging links’ is closed to new replies.