need direction with filtering
Hi there,
I've spent quite a bit of time on searching and trying to understand other posts on filtering and am still stuck, I'm very new to PHP and would appreciate some direction.
I have an inventory page listing categories which I created using a WP page template, it appears as www.mysite.com/inventory, i got this to work. Each category will link to its own page which I've defined in the PODS page section as inventory/* .... so that part works fine where when category01 is clicked on you get the page www.mysite.com/inventory/category01.
The issue i'm having is getting the proper filtered lists to appear on the inventory/* pages. I would like the items to appear in table format as each item has a photo and specs. This is probably something very easy but for the life of me I cannot figure it out.
Any guidance is great appreciated. If you need more info please let me know.
thank you.
7 Answers
I've gone through your site in detail and here's the code I used for the Pod Page:
<pre> <?php global $pods; ?> <div id="col-right"> <div class="post"> <h2><?php echo $pods->get_field('name'); ?></h2> <div class="entry"> <table width="98%" border="0" cellspacing="0" cellpadding="5" id="inventorytable"> <thead> <tr> <th align="center" bgcolor="#FFFFCC"><strong>Picture</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Name</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Size</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Manufacturer</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Colour(s)</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Description</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Quanitity Available</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Quality</strong></th> <th align="center" bgcolor="#FFFFCC"><strong>Price</strong></th> </tr> </thead> <tbody> <?php $product = new Pod('product'); $product->findRecords('name ASC',-1,'category.id='.$pods->get_field('id')); $total_products = $product->getTotalRows(); while($product->fetchRecord()) { $product_name = $product->get_field('name'); $product_photo = $product->get_field('photo.guid'); $product_size = $product->get_field('size'); $product_manufacturer = $product->get_field('manufacturer'); $product_description = $product->get_field('description'); $product_color = $product->get_field('color'); $product_quantity = $product->get_field('quantity'); $product_quality = $product->get_field('quality'); $product_price = $product->get_field('price'); ?> <tr> <td><div style="width: 90px; overflow: hidden;"><?php if($product_photo!==false){ ?><img src="<?php echo $product_photo; ?>" alt="Photo of <?php echo $product_name; ?>" height="63" /><?php } else { ?>--<?php } ?></div></td> <td><?php echo $product_name; ?></td> <td><?php echo $product_size; ?></td> <td><?php echo $product_manufacturer; ?></td> <td><?php echo $product_description; ?></td> <td><?php echo $product_color; ?></td> <td><?php echo $product_quantity; ?></td> <td><?php echo $product_quality; ?></td> <td><?php echo $product_price; ?></td> </tr><!-- /product list --> <?php } ?> </tbody> </table> </div> </div> <img src="<?php bloginfo('stylesheet_directory'); ?>/images/spacer.gif" alt="clear" width="1" height="1" border="0" class="clearme" /> </div> </pre>
And here's the precode: <pre> <?php $pods = new Pod('product_category',pods_url_variable(-1)); if(empty($pods->data)) { wp_redirect('../',301); die(); } </pre>
And here's the page template code: <pre> <?php /* Template Name: Inventory - List */ get_header(); ?> <div id="content"> <?php pods_content(); ?> <img src="<?php bloginfo('stylesheet_directory'); ?>/images/spacer.gif" alt="clear" width="1" height="1" border="0" class="clearme" /> </div><!-- end content --> <?php get_sidebar(); get_footer(); ?> </pre>
An update, and if anyone can still help please do!
I'm using Wordpress themed pages to do this. I have a page that displays my categories pod which will be viewed as www.mysite.com/inventory, this is the code:
<pre> <?php $category = new Pod('product_category'); $category->findRecords('name ASC'); $total_categories = $category->getTotalRows(); ?>
<?php if( $total_categories>0 ) : ?>
<?php while ( $category->fetchRecord() ) : ?>
<?php // set our variables $category_name = $category->get_field('name'); $category_photo = $category->get_field('photo'); $category_slug = $category->get_field('permalink');
// data cleanup $category_photo = $category_photo[0]['guid']; ?>
<div class="category_block">
<div class="category_image">
<a href="<?php echo get_permalink(); ?><?php echo $category_slug; ?>/">
<img src="<?php echo $category_photo; ?>" alt="Photo of <?php echo $category_name; ?>" />
</a></div>
<h2><a href="<?php echo get_permalink(); ?><?php echo $category_slug; ?>/">
<?php echo $category_name; ?>
</a></h2>
</div><!-- /category -->
<?php endwhile ?>
<?php endif ?> </pre>
This spits out my categories plus an image and a link to it's page using the permalink (slug) i set up for the category Pod.
I have a second pod for the products. Each product will belong to a category which i've set up using the Column type 'relationship (pick)'. I've also set up another WP theme page that spits out ALL the products in a table format... see here:
<pre>
<table>
<?php
$product = new Pod('product');
$product->findRecords('name ASC');
$total_products = $product->getTotalRows();
?>
<?php if( $total_products>0 ) : ?>
<?php while ( $product->fetchRecord() ) : ?>
<?php // set our variables $product_name = $product->get_field('name'); $product_photo = $product->get_field('photo'); $product_size = $product->get_field('size'); $product_manufacturer = $product->get_field('manufacturer'); $product_description = $product->get_field('description'); $product_color = $product->get_field('color'); $product_quantity = $product->get_field('quantity'); $product_quality = $product->get_field('quality'); $product_price = $product->get_field('price');
// data cleanup $product_photo = $product_photo[0]['guid']; ?> <tr> <td><div style="width: 90px; overflow: hidden;"><img src="<?php echo $product_photo; ?>" alt="Photo of <?php echo $product_name; ?>" height="63" /></div></td> <td><?php echo $product_size; ?></td> <td><?php echo $product_manufacturer; ?></td> <td><?php echo $product_description; ?></td> <td><?php echo $product_color; ?></td> <td><?php echo $product_quantity; ?></td> <td><?php echo $product_quality; ?></td> <td><?php echo $product_price; ?></td> </tr> <!-- /product list -->
<?php endwhile ?> <?php endif ?> </table> </pre>
The issue i'm having is how to filter the products per category, as each category will have it's own page listing it's products. This page will ultimately be the page template for inventory/* and spit out www.mysite.com/inventory/permalink.
Please help! I don't know how to relate the two pods to pull the info i need.
thank you.
@pixelarcher I think I understand what you're trying to do, but I'm little confused on whether you're trying to use Pods built in filters or create custom ones.
Anywho, one strategy, if you just want users to be able to filter the products on the Products WP Page you've already set up is to just set up custom form that directs action at the product page. Something like this should work:
<pre> <form action='' method="get"> <select name="prodcat"> <?php $cat = new Pod('product_category'); $cat->findRecords('name ASC', -1); while($cat->fetchRecord()) { $cat_id = $cat->get_field('id'); $cat_name = $cat->get_field('name'); echo '<option value="' .$cat_id '">' .$cat_name .'</option>'; } ?> </select> <input type="submit" name="submit" value="Submit Filter"> </form> </pre>
This method will append a ?prodcat=ID to your url. Then in you can alter your pods code in the following manner.
<pre> <?php $prodcat = $_GET['prodcat']; $product = new Pod('product'); if(isset($prodcat)) { $product->findRecords('name ASC', -1, "category.id = '$prodcat'"); } else { $product->findRecords('name ASC'); } $total_products = $product->getTotalRows(); ?> </pre>
While this method should work, you're missing out on some of the ease of using pods. by setting up a "product-list" page that calls a "product-list" template, this functionality will be built in. Just use the getFilters() function to call the filters into the product page.
To clarify. I would instead recommend creating a pod page list/* and then use the following code:
<pre> <?php $cat = pods_url_variable('last'); $products = new Pod('product'); $products->findRecords('name ASC',-1, "product_category.slug = '$cat'); $rows = $products->getTotalRows(); if( $rows > 0 ) { echo $products->showTemplate('your-list-template'); } else { echo 'There are no products in this category'; } ?> </pre>
Am I making sense?
Hi mpvanwinkle , thank you for taking the time with my post. I read through your responses and I'm still confused. I was basically taking the Pods Basics tutorial over at Monday by Noon to get where I am with the code by using the WP theme templates.
My two pods are 'product_category' - which are my categories, and 'product' - which I want to list per category, sort of like an online shop would have it's categories, then each would link to a page with the products listed... but I don't need the detailed pages for each individual product, just the category which points to the lists respectively in table format as I had in my previous post. (this is how my client needs it to be)
I would like to use the PODs built in filters, i thought that is what the permalink (slug) I set up in my 'product_category' POD would help me achieve?
The url i have for each category is <pre> <a href="<?php echo get_permalink(); ?><?php echo $category_slug; ?>/"> </a> </pre>
this would give me the proper www.pixelarcher-example.com/inventory/* url.
But how do i get the list of proper products to show up at the inventory/* location?
Can i still use the WP themed pages? and then just choose that as my 'page template' in the PODS > Pages > inventory/* area? That's what i did with your suggested code above but i got an error... noticed a missing " , I put that in, error was gone but nothing was listed.
thanks for your patience.
Thanks Scott! I'm looking it over right now. I'll email you soon.


