Update the shop page to properly use the prepare method.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Jul 2016 13:37:57 +0000 (09:37 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 28 Jul 2016 13:37:57 +0000 (09:37 -0400)
When using the prepare method you need to have %d or %s at least once in
the sql part and give a paramater for that replacement part.

style.css
woocommerce.php

index 0572052..4a4c99b 100644 (file)
--- a/style.css
+++ b/style.css
@@ -3,5 +3,5 @@ Theme Name: FranceJourneys
 Author: Gaslight Media
 Author URI: http://www.gaslightmedia.com
 Description: A theme for FranceJourneys
-Version: 1.0.4
+Version: 1.0.5
 */
index eecb4c0..5d66d88 100644 (file)
@@ -6,7 +6,7 @@
     <?php get_template_part('parts/bread-crumbs'); ?>
 </div>
 <main class="page-inside woocommerce">
-    
+
     <div id="content-wrapper" class='side-shadow woocommerce-wrapper'>
         <div class="row">
             <?php if ( ! is_product_tag() && ! is_product_category()) { ?>
@@ -16,7 +16,7 @@
             <?php } ?>
             <?php if (is_shop()) { ?>
                 <div class="small-12 large-9 columns main woo-tags">
-  
+
                 <?php
                         /**
                          * woocommerce_before_main_content hook
@@ -34,7 +34,7 @@
 
                                 <small class="product_category_title_item"><?php echo $single_cat->name; ?></small>
 
-                      <?php 
+                      <?php
                             }
                         }
                         add_action( 'woocommerce_after_shop_loop_item_title', 'wc_category_title_archive_products', 5 );
@@ -51,8 +51,8 @@
                <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
 
                <?php endif; ?>
-                        
-                        <?php woocommerce_content();?> 
+
+                        <?php woocommerce_content();?>
 
                <?php do_action( 'woocommerce_archive_description' ); ?>
 
                     if ( $product_cats && ! is_wp_error ( $product_cats ) ){
 
                         $single_cat = array_shift( $product_cats );
-                        
+
                         // Set name to the default first picked category (however WC decides that)
                         $primaryCatName = $single_cat->name;
-                        
+
                         // Try to get the Primary Category based on how Yoast SEO has set it in the postmeta table
                         global $wpdb;
                         $sqlGetPrimary = "SELECT meta_value
                                 FROM $wpdb->postmeta
                                 WHERE
-                                    (meta_key = '_yoast_wpseo_primary_product_cat' AND post_id = '". get_the_id() ."');
+                                    (meta_key = '_yoast_wpseo_primary_product_cat' AND post_id = %d);
                         ";
-                        $primaryCatID = $wpdb->get_var($wpdb->prepare($sqlGetPrimary));
+                        $primaryCatID = $wpdb->get_var(
+                            $wpdb->prepare(
+                                $sqlGetPrimary,
+                                get_the_id()
+                            )
+                        );
                         $term = get_term_by( 'id', $primaryCatID, 'product_cat' );
-                        
+
                         // Use the primary category instead if it's valid
                         if( $term->name ) {
                             $primaryCatName = $term->name;
                         }
                     ?>
-                    
-                    <small class="product_category_title_item"><?php echo $primaryCatName; ?></small>          
-                    
+
+                    <small class="product_category_title_item"><?php echo $primaryCatName; ?></small>
+
                     <?php }
                     }
                     add_action( 'woocommerce_after_shop_loop_item_title', 'wc_category_title_archive_products', 5 );
                             $columns = 3;
                             return $columns;
                         }
-                    } 
+                    }
                     ?>
 
                <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
                 </div>
             <?php } else if (is_product()) { ?>
                 <div class="small-12 large-9 columns main woo-single-product">
-                    <?php      
-                        if(function_exists('pf_show_link')){echo pf_show_link();} 
+                    <?php
+                        if(function_exists('pf_show_link')){echo pf_show_link();}
                     ?>
                     <?php
                             /**
     </div>
 <?php get_footer(); ?>
 <script>
-    
+
 $(document).ready(function () {
     $("#tab-html5_video p").remove();
     var mainImage = $(".attachment-shop_single.size-shop_single.wp-post-image");
@@ -224,7 +229,7 @@ $(document).ready(function () {
     // Thumbnail undisplay
     $(thumbImage).mouseout(function(){
         $(mainImage).attr("srcset", $(mainImage).attr("src"));
-    }); 
-    
+    });
+
 });
-</script>
\ No newline at end of file
+</script>