Support

Account

Home Forums Front-end Issues Output a page for a field value?

Solved

Output a page for a field value?

  • Is it possible to output a theme template-like page corresponding to an ACF field value?

    I have a taxonomy, “company”. Each “company” term has an ACF field group applied, containing mostly Checkboxes…

    The Checkbox in question is “tags“, whose values effectively sub-describe the type of company.

    I would like to know if I can output a page for each “tag” Checkbox value.
    eg. output a “Publishing” page corresponding to the “Publishing” tag which would list all “companies” tagged with the ACF Checkbox “tag” value “Publishing”.

    Preferably, this would be dynamic rather than fixed – ie. would accommodate any possible existing “tag” value, rather than require I create a number of pages for each.

    Had I chosen to apply a standard WordPress taxonomy to the primary “company” taxonomy, of course, this functionality would have been built-in. But I chose to apply a field group for reasons discussed in an earlier thread.

    Thanks!

  • You used a field group, but did you use a taxonomy field or eventually create a custom taxonomy? If this were the case the standard WP template hierarchy would manage this by creating a template for the taxonomy. I’m not sure if I covered that or not in the other discussion.

    If not then this is going to be difficult to do. There may be other methods, but this is what I would do if I needed to create a dynamic page based on only an ACF field.

    1) I would create a “Page” post. This will be used similar to the WP page_on_front or page_for_posts, page. It’s basically a place holder page.

    2) I would create a custom template file to be used on this page. This template file would dynamically generated.

    3) Links would need to include a query variable, for example ?company-type=some-company-type

    4) Use the query variable in 3 to dynamically generate the content for 2

    Alternately, instead of a query string variable in the url you could have the page named something like `https://www.yoursite.com/company-type/{$COMPANY_TYPE} and then add custom rewrite rules to WP to transform the URL and add the correct query string. I would probably do this, but the details of doing this are not something I know off the top of my head.

  • You used a field group, but did you use a taxonomy field or eventually create a custom taxonomy

    Whilst I experimented with this, I chose ACF Checkbox for all such “company” sub-descriptions, as there are multiple of them. On the one hand, I feared over-use of taxonomies but, on the other, it would have certainly afforded me native taxonomy term page creation like this.

    So,

    Method 1) Page:
    Write a template file, apply it to a Page and pass the ACF Checkbox “tag” values to the Page, in a link from wherever I’m linking. I guess I’m going to need to learn how a Page can pick up those parameters and how to interpret them (Eg. https://dmjcomputerservices.com/blog/passing-url-parameters-to-a-wordpress-page/ ?)

    Method 2) Rewrite rules:
    So the page in this case is “company-type”?

    And then add custom rewrite rules to WP to transform the URL and add the correct query string

    So would this effectively be the same method as Method 1), ie. it needs to utilise URL query string parameters? And then it just uses rewrites to make the user-facing URLs prettier?

    Thanks.

  • Yes, method 2 is the same as method 1, it just gives you pretty urls. This is the way I would go because I work for an SEO company and they would insist on having pretty urls. I’ve done similar things in the past, but it takes me longer that it should because I don’t do it frequently enough and I always run into problems. For example, the last time I did it I forgot that I had to register my query variable with WP so it was not being passed in correctly. When you use rewrite rules you need to use WP functions to register and to get the variable, while in method 1 your can just access $_GET values directly.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.