I have custom field "Fruit" with value "Orange" and others, I want to use a short code that should display all posts on a page for "Orange" value by URL parameter. for example below URL should show all posts on a page related to "orange": www.domain.com/?fruit=orange
I've very basic expertise of WordPress development and couldn't find any solution yet.
Currently I'm using this short code to display posts, but want to filter posts by URL parameters
function my_pre_get_posts( $query ) {
$the_query = new WP_Query('meta_key=fruit');
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<div class="fruits">';
echo '<div class="content">'; the_post_thumbnail('thumbnail'); echo '</div>';
echo '<div class="title">'; the_title(); echo '</div>';
$slug = get_post_field( 'post_name', get_the_ID() );
echo '<div class="readMore"> <a href="'.$slug.'"> Read More </a>';
echo '</div>';
endwhile;
// Reset Post Data
wp_reset_postdata();
}
add_shortcode('pre_get_posts', 'my_pre_get_posts');