Firstly, don't use
It should be noted that using this to replace the main query on a page
can increase page loading times, in worst case scenarios more than
doubling the amount of work needed or more. While easy to use, the
function is also prone to confusion and problems later on. See the
note further below on caveats for details.
Secondly, it really sounds like you're taking the wrong approach here. When you say:
so I can generate more pages using 1 templates for different
Do you realise WordPress automatically creates pages for post type and taxonomy archives? You just need to have the post type and taxonomy be public. WordPress will pick the appropriate template for these pages based on the Template Hierarchy.
But regarding using ACF fields in query arguments (whether in
WP_Query), the issue is two things:
- You need to use a function that returns a value, rather than outputting it to the screen. See the answers to this Stack Overflow question for more information on the difference.
- You're trying to use a function inside a string (text between quotes
Since Advanced Custom Fields' function for returning a field value is
get_field(), you would use it like this:
'taxonomy' => get_field( 'posttype_name' ),
Pay close attention to where
, are used, compared to your attempt.