• I am trying to create a form on a website of mine that lets you select a minimum price ($minprice), a maximum price ($maxprice), and a product category ($product_category) and then displays a list of products within that category ordered by rating.

    I have created a custom post type:

    Product

    I am using the following custom taxonomies:

    Price
    Product Category
    Rating

    I found this code in the Codex, however it says that it is for custom fields and not custom taxonomies.

    <?php
    $meta_key1 = 'model';
    $meta_key2 = 'year';
    $meta_key3 = 'manufacturer';
    $meta_key3_value = 'Ford';
    
    $postids=$wpdb->get_col($wpdb->prepare("
    SELECT      key3.post_id
    FROM        $wpdb->postmeta key3
    INNER JOIN  $wpdb->postmeta key1
                on key1.post_id = key3.post_id
                and key1.meta_key = %s
    INNER JOIN  $wpdb->postmeta key2
                on key2.post_id = key3.post_id
                and key2.meta_key = %s
    WHERE       key3.meta_key = %s
                and key3.meta_value = %s
    ORDER BY    key1.meta_value, key2.meta_value",$meta_key1, $meta_key2, $meta_key3, $meta_key3_value)); 
    
    if ($postids) {
      echo 'List of ' . $meta_key3_value . '(s), sorted by ' . $meta_key1 . ', ' . $meta_key2;
      foreach ($postids as $id) {
        $post=get_post(intval($id));
        setup_postdata($post);?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      }
    }
    ?>

    Does the fact that I am using a custom post type with custom taxonomies instead of a regular post with custom fields affect the way that I would have to use this code?

    Also, can anyone add a little code that would restrict results to only products within the price range set by the form?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Sam Brodie

    (@sammybeats)

    I think I’ve figured out how to restrict the price (with a BETWEEN clause), however I’m still wondering:

    Does the fact that I am using a custom post type with custom taxonomies instead of a regular post with custom fields affect the way that I would have to use this code?

    And if someone could explain to me where key3.post_ID comes from that would be great as well.

    Thank you!

    Thread Starter Sam Brodie

    (@sammybeats)

    No one can help me with this question?

    Thread Starter Sam Brodie

    (@sammybeats)

    Does anyone know another forum where I might be able to have this question answered?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Using Custom Taxonomy and Custom Fields Interchangeably’ is closed to new replies.