• Is it possible to use a shortcode (within the html editor) to alter the page template file (selected for that specific page) to send variables to the template file?

    For example: I have added a template called Vehicles to my page. Normally this would show me all vehicles. But I want to filter that specific page only on rentals. So I would add a shortcode [vehicles type=”rental”]. Adding the shortcode function to functions.php is not a problem, but setting a variable that can be read in the template file is.

    I have tried it with globals, sessions etc. but nothing is working. Can someone please help?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I don’t think shortcodes are the way to go for this. They’re really meant to be like compressed content that is expanded when the content filter is run. Custom fields might be a better approach as you could then check the field’s value within the page’s template file to determine how to run your custom query.

    Thread Starter rs011

    (@sandurtjuh)

    Alright, thanks.
    I was kind of thinking that was the way to go, but now I got confirmation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use shortcode to alter template file’ is closed to new replies.