• Resolved Jorim

    (@jorim)


    I’m running a website about music. So we have post types like review, concert, interview etc. And one of the postmeta fields we register on post level is the (record) label.

    A review could have the following URL: example.com/review/artist-name-album-name/

    I’d like create a ‘archive’ page or pages for the labels too. So the URL should become something like this: example.com/label/label-name/

    This page will show all posts that have a postmeta key label with postmeta value label-name.

    I tried to find something that looks like this to get me started, but I couldn’t find anything. I have two main questions here:
    – Is it the best / easiest way to create a page, label, in WP and link it to a specific custom template?
    – How to get the 2nd level (example.com/label/label-name/) send as a parameter to the ‘page’ so I can retrieve posts for it?

    Thanks in advance for helping out!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I would suggest looking into using a custom taxonomy instead of post_meta. You can limit it certain post types and you will automatically get taxonomy archive pages (i.e. example.com/label/label-name/) and the database queries are much more efficient that doing meta queries.

    • This reply was modified 7 years, 11 months ago by jkovis.
    Moderator bcworkz

    (@bcworkz)

    Any time you create a page it is related to a template. If there is only one page template, the option is not displayed. As soon as more than one template is available, an option will be available in the meta box with the page parent.

    Pages can be queried by their template as a meta data query, but there is no standard permalink to do so. A custom one could be created by adding a rewrite rule.

    I agree with jkovis that a taxonomy is a good solution to get various post types through a single term. There is one small issue with taxonomy terms, it’s rather tricky to order queries by taxonomy terms. Not impossible, but it’s not supported by the usual WP_Query class. It can order by meta data, but not terms. If you do not anticipate such a need, taxonomies will be fine. If the need arises in the future, the solution is to write a custom SQL query and use $wpdb methods.

    Thread Starter Jorim

    (@jorim)

    I tried some things with a custom rewrite rule, but I ended up with custom taxonomies. I still use the custom fields, but I create the (concatenated) taxonomies during post saving.

    So you both were absolute right about taxonomies being the right solution ?? Thanks for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to create a post meta key / value page’ is closed to new replies.