admin管理员组

文章数量:1430548

For SEO purposes I use my URLs like this:

site/parent/child/

Currently I have pages like this:

site/parent/

site/page-1/

site/page-2/

site/page-3/

I want to list some of those page-1, page-2 etc. pages on site/parent/ I thought the best way to do this is to add a custom field to those.

So is there a better way to do this? If not, how can I wp list pages based on custom fields?

For SEO purposes I use my URLs like this:

site/parent/child/

Currently I have pages like this:

site/parent/

site/page-1/

site/page-2/

site/page-3/

I want to list some of those page-1, page-2 etc. pages on site/parent/ I thought the best way to do this is to add a custom field to those.

So is there a better way to do this? If not, how can I wp list pages based on custom fields?

Share Improve this question asked Apr 24, 2019 at 9:33 Markus HansenMarkus Hansen 311 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

Function wp_list_pages() accepts arguments from get_pages() function. To list pages filtered by custom field use meta_key and meta_value in parameters array. A list of accepted parameters can be found here and here.

wp_list_pages([
    'meta_key' => 'your_meta_KEY',
    'meta_value' => 'searched_value', // optional
]);

meta_value is not mandatory, if you skip it, a list of pages with any value of the custom field will be returned.

本文标签: List pages by custom field