Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination on related posts query #21

Closed
hgodinho opened this issue Feb 8, 2019 · 1 comment
Closed

Pagination on related posts query #21

hgodinho opened this issue Feb 8, 2019 · 1 comment

Comments

@hgodinho
Copy link

hgodinho commented Feb 8, 2019

On issue #20 I talked about two custom post-types that I created: authors and artworks.
Ive made a single-author template and then queried the relationships on artworks, but I couldnt get the pagination to work. Am I missing something?

The CPT declaration:

        register_post_type(
            'autores',
            array(
                'supports' => array(
                    'title',
                    'revisions',
                    'comments',
                ),
                'public' => true,
                'publicly_queryable' => true,
                'show_in_menu' => false,
                'has_archive' => true,
                'hierarchical' => true,
                'rewrite' => array(
                    'slug' => PLUGIN_SLUG . '/autor',
                    'with_front' => false,
                    'pages' => true,
                ),
            )
        );

The query:

$args = array(
    'post_type' => 'obras',
    'post_status' => 'any',
    'relationship' => array(
        'id' => 'obras_to_autores',
        'to' => $post->ID,
    ),
    'posts_per_page' => 6,
    'paged' => 0,
);
$connected = new WP_Query($args);

When I click the number of the pagination menu, it redirects to the same page

@rilwis
Copy link
Member

rilwis commented Feb 25, 2019

Hi @hgodinho ,

The URL you're viewing only works for default WordPress's pagination. If you want to paginate the related items, then you have to do that on your own by: setting up a custom query var and parse that query var and pass to the relationship query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants