Skip to main content
added 229 characters in body
Source Link
SixfootJames
  • 437
  • 3
  • 11
  • 23

EDIT

I've looked again at the DB, the product from wp_posts through to wp_postmeta and filtered meta_value by "Paper" and they all return the following a:1:{i:0;s:9:"Paper";} where I supposedly should have just "Paper"

EDIT

I've looked again at the DB, the product from wp_posts through to wp_postmeta and filtered meta_value by "Paper" and they all return the following a:1:{i:0;s:9:"Paper";} where I supposedly should have just "Paper"

added 468 characters in body
Source Link
SixfootJames
  • 437
  • 3
  • 11
  • 23

EDIT:

This is what my array looks like now:

$args = array(
    'post_type' => 'Product', 
    'posts_per_page' => -1, 
    'orderby' => 'title', 
    'order' => 'ASC',
    'meta_query' => array(
           array(
               'key' => 'product_type'
           )
        )

);

Just the "key" alone does the trick right, but as soon as I add the "value" the search does not return any results. And I know that the value should be "Paper" in this case.

EDIT:

This is what my array looks like now:

$args = array(
    'post_type' => 'Product', 
    'posts_per_page' => -1, 
    'orderby' => 'title', 
    'order' => 'ASC',
    'meta_query' => array(
           array(
               'key' => 'product_type'
           )
        )

);

Just the "key" alone does the trick right, but as soon as I add the "value" the search does not return any results. And I know that the value should be "Paper" in this case.

Source Link
SixfootJames
  • 437
  • 3
  • 11
  • 23

Querying Advanced Custom Fields

I've been back and forth with this and not able to get my Advanced Custom Field query working.

According to the documentation in the link above, this is what my array should look like:

$args = array(
    'numberposts' => -1,
    'post_type' => 'event',
    'meta_key' => 'location',
    'meta_value' => 'Melbourne'
);

Below is my array. The problem is clearly in the meta_key and meta_value I am trying to query. Without the meta_key and meta_value, all the Products are being returned as expected. I have been into the database to make sure I have the right values so this looks correct to me. Is there something that stand out to anyone I might be missing? Thanks

        <section class="entry-content clearfix search-results sectiondrop" itemprop="articleBody">
            <h3>Search Results</h3>
            <?php 
                $args = array( 
                    'post_type' => 'Product', 
                    'posts_per_page' => -1, 
                    'orderby' => 'title', 
                    'order' => 'ASC', 
                    'meta_key' => 'product_type',
                    'meta_value' => 'Paper'
                );
                $loop = new WP_Query( $args ); ?>
                <ul>
                <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
                    
                        <li>
                            <strong><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a> - <?php the_field('product_type'); ?></strong><br>
                            <?php the_field('product_description'); ?><br><br>
                        </li>
                    
                <?php endwhile; ?>
                <?php wp_reset_query(); ?>
                </ul>
            <?php } ?>
        </section>