• Hi, I’m pretty new to all of this and am having a little trouble with a website I’ve recently designed http://www.luxxbox.com.au. On pages such as http://www.luxxbox.com.au/furniture I run the following code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    The point of this code is to select images labeled as hero whose titles match those of the pages which are children of the current page and display them in order based on the value in post_content. These images are then echoed as list items displayed in a carousel linking to their related page. The whole thing seems quite messy but the biggest problem is that using foreach to run the sql query over and over again is making for ridiculously long page generation times.

    My one thought I’ve had is if there was some way to output the page titles (or IDs) from get_page as a single line seperated by “OR”, store this in a variable and then input it into the sql query then it would avoid the large number of queries I currently use.

    For example get_pages outputs the page titles a b c then this gets saved as a variable $x=a OR b OR c; and then I use this variable in the query “SELECT * FROM wp_posts WHERE post_title=(‘” . $x . “‘”);.

    Maybe there’s a really nice simple way to do this that I’ve missed because of my inexperience. Any help would be greatly appreciated!

Viewing 1 replies (of 1 total)
  • Thread Starter chatotek

    (@chatotek)

    I think I might have made my question a bit complicated by giving so much information. I think I can solve the problem on my own if someone can explain to me if it’s possible to get something like this to work:

    <?php
    $parent_page = $post->ID;
    $pages = get_pages('child_of='.$parent_page.'');
    $single_line = implode("OR", $pages);
    echo $single_line;
    ?>

    Echoing $single_line would output “ID1 OR ID2 OR ID3” etc. where ID1 is the ID of child one.

Viewing 1 replies (of 1 total)
  • The topic ‘Return page children for use in SQL query’ is closed to new replies.