Skip to main content
added 7 characters in body
Source Link

I need to create a custom query for the author archive (where the author is post_author OR is a meta co_author), and it have to work with WP Pagenavi.

The query is something like this (omitting $wpdb and usual clauses for clarity):

SELECT posts.*
FROM posts, postmeta
WHERE
    posts.ID = postmeta.post_id AND
    (posts.post_author = $author OR
        (postmeta.meta_key = 'co_author' AND
         postmeta.meta_value = $author)
    )

I've already tried with no success:

  • using LIMIT and OFFSET with query_var($paged) and 'posts_per_page' option, but Pagenavi total pages are the same as the query was the default author archive one;
  • adding a where filter (' OR posts.post_author = $author') to a custom WP_Query checking for meta_key/value only, but Pagenavi completely disregards the filter;
  • other stuff I actually cannot remember because I've tried them last night between 3 and 5 AM but I'm sure they didn't work...

The actual problem is that I can't find a way to check "meta_query OR post_author" using just the WP_Query argument array, like:

$the_query = new WP_Query(array(
    'post_author'    => $author,
    /* OR */
    'meta_query'     => array(
        array(
            'key'    => 'co_author',
            'value'  => $author
        )
    )
));

Unfortunately, I'm not really confident with query filters so I'm really really trying to find a simple workaround to make that work with Pagenavi. But, after plenty of hours on this issue, my mind isn't fresh anymore and I don't know how to proceed.

Thank you all in advance.

I need to create a custom query for the author archive (where the author is post_author OR is a meta co_author), and it have to work with WP Pagenavi.

The query is something like this (omitting $wpdb and usual clauses for clarity):

SELECT posts.*
FROM posts, postmeta
WHERE
    posts.ID = postmeta.post_id AND
    (posts.post_author = $author OR
        (postmeta.meta_key = 'co_author' AND
         postmeta.meta_value = $author)
    )

I've already tried with no success:

  • using LIMIT and OFFSET with query_var($paged) and 'posts_per_page' option, but Pagenavi total pages are the same as the query was the default author archive one;
  • adding a where filter (' OR posts.post_author = $author') to a custom WP_Query checking for meta_key/value only, but Pagenavi completely disregards the filter;
  • other stuff I actually cannot remember because I've tried them last night between 3 and 5 AM but I'm sure they didn't work...

The actual problem is that I can't find a way to check "meta_query OR post_author" using just the WP_Query argument array, like:

$the_query = new WP_Query(
    'post_author'    => $author,
    /* OR */
    'meta_query'     => array(
        array(
            'key'    => 'co_author',
            'value'  => $author
        )
    )
);

Unfortunately, I'm not really confident with query filters so I'm really really trying to find a simple workaround to make that work with Pagenavi. But, after plenty of hours on this issue, my mind isn't fresh anymore and I don't know how to proceed.

Thank you all in advance.

I need to create a custom query for the author archive (where the author is post_author OR is a meta co_author), and it have to work with WP Pagenavi.

The query is something like this (omitting $wpdb and usual clauses for clarity):

SELECT posts.*
FROM posts, postmeta
WHERE
    posts.ID = postmeta.post_id AND
    (posts.post_author = $author OR
        (postmeta.meta_key = 'co_author' AND
         postmeta.meta_value = $author)
    )

I've already tried with no success:

  • using LIMIT and OFFSET with query_var($paged) and 'posts_per_page' option, but Pagenavi total pages are the same as the query was the default author archive one;
  • adding a where filter (' OR posts.post_author = $author') to a custom WP_Query checking for meta_key/value only, but Pagenavi completely disregards the filter;
  • other stuff I actually cannot remember because I've tried them last night between 3 and 5 AM but I'm sure they didn't work...

The actual problem is that I can't find a way to check "meta_query OR post_author" using just the WP_Query argument array, like:

$the_query = new WP_Query(array(
    'post_author'    => $author,
    /* OR */
    'meta_query'     => array(
        array(
            'key'    => 'co_author',
            'value'  => $author
        )
    )
));

Unfortunately, I'm not really confident with query filters so I'm really really trying to find a simple workaround to make that work with Pagenavi. But, after plenty of hours on this issue, my mind isn't fresh anymore and I don't know how to proceed.

Thank you all in advance.

Source Link

Custom query (author is post_author or meta co_author) with Pagenavi pagination

I need to create a custom query for the author archive (where the author is post_author OR is a meta co_author), and it have to work with WP Pagenavi.

The query is something like this (omitting $wpdb and usual clauses for clarity):

SELECT posts.*
FROM posts, postmeta
WHERE
    posts.ID = postmeta.post_id AND
    (posts.post_author = $author OR
        (postmeta.meta_key = 'co_author' AND
         postmeta.meta_value = $author)
    )

I've already tried with no success:

  • using LIMIT and OFFSET with query_var($paged) and 'posts_per_page' option, but Pagenavi total pages are the same as the query was the default author archive one;
  • adding a where filter (' OR posts.post_author = $author') to a custom WP_Query checking for meta_key/value only, but Pagenavi completely disregards the filter;
  • other stuff I actually cannot remember because I've tried them last night between 3 and 5 AM but I'm sure they didn't work...

The actual problem is that I can't find a way to check "meta_query OR post_author" using just the WP_Query argument array, like:

$the_query = new WP_Query(
    'post_author'    => $author,
    /* OR */
    'meta_query'     => array(
        array(
            'key'    => 'co_author',
            'value'  => $author
        )
    )
);

Unfortunately, I'm not really confident with query filters so I'm really really trying to find a simple workaround to make that work with Pagenavi. But, after plenty of hours on this issue, my mind isn't fresh anymore and I don't know how to proceed.

Thank you all in advance.