Hey @dad0,
To display all products with a specific value (like GENRE|JUNIOR) in the custom field meta_easyfatt_libero_1 on your site, you can create a custom template file and a new page using that template. Here’s how you can achieve this:1. Create a Child Theme (if you don’t already have one):
Creating a child theme ensures that your customizations won’t be lost when the parent theme is updated.
- Step 1: Navigate to
wp-content/themes/ using FTP or your hosting file manager.
- Step 2: Create a new folder called
yourtheme-child (replace “yourtheme” with the name of your active theme).
- Step 3: Inside the
yourtheme-child folder, create two files: style.css and functions.php(optional).
- Step 4: In
style.css, add the following code:
/*
Theme Name: YourTheme Child
Template: yourtheme
*/
- Step 6: Go to your WordPress admin dashboard, then go to
Appearance > Themes, and activate the YourTheme Child theme.
2. Create a Custom Template File:
- Step 1: Inside your child theme folder (
yourtheme-child), create a new file called template-easyfatt-products.php.
- Step 2: Open this file and add the following code:
<?php
/* Template Name: Easyfatt Products */
get_header(); ?>
<div class="easyfatt-products-list">
<h1>Products with GENRE | JUNIOR</h1>
<?php
// Query products with meta_easyfatt_libero_1 containing GENRE|JUNIOR
$args = array(
'post_type' => 'product',
'meta_query' => array(
array(
'key' => 'meta_easyfatt_libero_1',
'value' => 'GENRE|JUNIOR',
'compare' => 'LIKE',
),
),
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post(); ?>
<div class="product">
<h2><?php the_title(); ?></h2>
<a href="<?php the_permalink(); ?>">View Product</a>
</div>
<?php }
} else {
echo '<p>No products found with GENRE | JUNIOR.</p>';
}
wp_reset_postdata();
?>
</div>
<?php get_footer(); ?>
- Step 3: Save the file.
- Step 4: Create a functions.php file in your child theme folder if you don’t already have one and add the following code to enqueue styles for your custom template [optional: if you want to add custom styles]:
<?php
// Enqueue styles for your custom template
function enqueue_custom_styles() {
if (is_page_template('template-easyfatt-products.php')) {
wp_enqueue_style('custom-styles', get_stylesheet_directory_uri() . '/custom-styles.css');
}
}
add_action('wp_enqueue_scripts', 'enqueue_custom_styles');
3. Create a New Page Using the Template:
- Step 1: Go to
Pages > Add New in your WordPress dashboard.
- Step 2: Title the page something like “Products by Genre”.
- Step 3: In the
Page Attributes section on the right-hand side, select Easyfatt Products from the Template dropdown.
- Step 4: Publish the page.
4. View the Page:
- Step 1: After publishing the page, visit the URL (e.g.,
yoursite.com/products-by-genre/), and you should see all products that match GENRE|JUNIOR from the custom field meta_easyfatt_libero_1.
This approach provides you with a linkable page that displays all products with the value GENRE|JUNIOR in the custom meta field.
Thread Starter
dad0
(@dad0)
@sainathpoojary The filter works, but does not show product images. Here’s what it looks like:
https://postimg.cc/py9y0FgL
Also, there is no pagination. I would like the images to show 4 or 5 per line, and not vertically as now.