query_posts $pagename variable not working if page uses “&” symbol
I’m using the $pagename variable in a query_posts string to pull subpages of defined page:
<?php $pagename = 'Products & Services'; $subpage_query = new WP_Query(); $subpage_query->query("pagename=$pagename"); ?>
I’m using this instead of wp_list_pages because I need to customise the output of the code. I’ve only included the query portion of the code for simplicity.
The problem is that when a page name contains a symbol such as the example above using “&”, the connection breaks. If I leave out the “&” symbol, all pages are listed, and if I type the name of a page that doesn’t exist, no pages are listed.
How do I get around this if a page title contains a symbol?
- The topic ‘query_posts $pagename variable not working if page uses “&” symbol’ is closed to new replies.