最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

List pages by custom field?

programmeradmin0浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论