• Resolved Jakob Smith

    (@diakrisis)


    Trying to build a page menu with wp_page_menu();

    I have made a database call to the wp_posts table in the WordPress database, asking for the IDs of pages matching certain conditions. I have put the the IDs into a commaseparated list in a PHP variable and now wants to use wp_page_menu(); like this:

    wp_page_menu('include=$IDvariable');

    But that returns nothing.

    Is it not possible to use PHP variables inside WP Template Tags?

    Does anyone have any idea how I get those IDs dynamically into wp_page_menu(); ?

    Or other suggestions on how to dynamically build a menu of pages matching certain conditions regarding a specific value in a specific field in the wp_posts database table?

    Regards,
    Jakob Smith

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try wp_page_menu('include=' . $IDvariable); and ensure that your variable is a simple string – not an array.

    The problem with your code is that you can’t use variables inside single quotes, so the value is treated literally.

    Esmi’s suggested code above will fix that by concatenating the string, alternatively you can also use double quotes so the variable is interpreted.

    Eg.

    wp_page_menu("include=$IDvariable");

    Thread Starter Jakob Smith

    (@diakrisis)

    The variable is indeed a simple string made with implode(); from an array.

    Both solutions work.

    Thanks! Really appreciate it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘PHP Variables in Template Tags?’ is closed to new replies.