1

I have custom field, array with multiple values

$metas = get_post_meta($post->ID, "$meta_key", false); 
foreach ( $metas as $metas ){
    echo $metas;    
}

Of course this will return an array.

How to paginate this? So for example:

www.example.com/post-title/1

will return meta_value[0]

and

www.example.com/post-title/2

will return meta_value[1]

and so on...

2

On a singular view, the current page number can be accessed with get_query_var('page'). You need to subtract 1 to get the corresponding array value. Note that the first page will redirect to the URL without page number, this is just a thing WordPress does.

// get meta
$metas = get_post_meta( $post->ID, 'your_meta_key', false );

// get page number
$page = get_query_var( 'page' );
$page = $page > 1 ? $page - 1 : 0;

// output meta for this page
if( isset( $metas[$page] ) ){
    echo $metas[$page];
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.