Here's what I'm trying to do. I made it so that the posts can store a postmeta value using a meta box textarea field.

Here's what I have done so far:

I extract the meta value and explode it to an array on line breaks, so I can access each value using the keys on the query by this function:

function custom_query_var( $vars ) {
    $vars[] = 'page_number';
    return $vars;
add_filter( 'query_vars', 'custom_query_var' );

The query is working using this url structure:


They are all displaying the array value of the postmeta that I exploded in the post template. When there's no query, it just displays the post, as I intended.

Now, I'm thinking of accessing them by a url structure like this:

http://domain.tld/post-slug/   -> for the post itself (no custom query)
http://domain.tld/post-slug/1/ -> for the post with a custom query

Here's what I've tried:

function custom_rewrite_rules() {
add_action('init', 'custom_rewrite_rules');

It doesn't seem to work, only displaying the post with no query happening. I'm not sure why, but I'm suspecting that I'm breaking a rule on 'posts' using the said rewrite rule. Can anyone enlighten me about this issue?

  • pagename is the query for page post type, not posts. Also note that a rule already exists with that pattern, for paginated singular posts. – Milo Apr 15 '17 at 16:41
  • I wonder of I can override tha pagination of singular posts then. I tried using the add_rewrite_endpoint() function to the init to make a post url query like domain.tld/post-name/query/1 and it's good, though I'd prefer overriding the post pagination if it can be done. – 58YtQ2H83m17838963l61BU07Y8622 Apr 15 '17 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.