Forums

query wp_posts and output results (2 posts)

  1. candell
    Member
    Posted 1 year ago #

    I am adding to a theme, one page of the theme needs a custom search.

    The site contains some property listings, the pages are created in a hierarchy i.e.

    for sale page
    area page (child of for sale)
    property name page (child of area)

    so the urls are

    http://www.site.com/for-sale/Staffordshire/Bob-Drive/

    there are several categories i.e. for sale, for rent, part buy etc each containing several areas and properties within each area.

    What I need to do is create a filterable search page, I am going to use jquery to provide the filtering so all I need to do with wordpress is to bring out all of the results and display these on the page. The filter is going to occur on the class name when output i.e. class='forsale staffordshire'. That would then show up on a filter for those criterea

    I hae gathered that I need to use wpdb to gather my results, but how do I gather them, then output to the page?

    So far I have

    <?php
    						$searchresults = $wpdb->get_results( "SELECT * FROM wp_posts" );
    						?>

    to start the query off, I need to write this to the page as

    <li class="propertytype area">
    <a href="link to property">Property name <img src="featuredimage"></a>
    </li>
    
    loop through etc

    Can someone lend a hand please?

    Many thanks

  2. candell
    Member
    Posted 1 year ago #

    I am getting closer, ignore the SQL at the moment as I need to figure out how to grab the name of the level above the properties to get the area.

    global $wpdb;
    
    $searchresults = $wpdb->get_results( "SELECT * FROM wp_posts where post_parent ='0'" );
    
    if ($searchresults)
    {
    global $post;
    foreach ($searchresults as $post)
    { 
    
    echo "<li><a href=''>".the_title()."</a></li>";
            }
          }

    but the output isn`t as I would expect, i.e. the page name is being printed outside of the list.

    e.g.

    Welcome

  3. Sample Page

  4. Homepage

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.