First, you have to determine from what category you want to display those products. If this happends on a single post display, you can get all post’s categories via wp_get_object_terms function
global $post;
$query_args[ 'category__in' ] = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) );
If this happens on a archive page, you can get the category id from query vars:
$query_args[ 'cat' ] = get_query_var('cat');
Check http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters for more details.
Related Posts:
- Create custom page in WooCommerce
- WooCommerce – Create Products Programatically [closed]
- How to Use PHP Code In-Page?
- Insert woocommerce products programmatically with featured image and gallery
- Problem with adding programmatically woocommerce product post into category
- Skip in WordPress Post ID’s, can this cause issues?
- How do I change the core post search algorithm? Where is it found/constructed?
- Show posts count for Categories and Tags in wp_nav_menu
- Is it possible to automatically publish a post once a woo-commerce product is published?
- Restore woocommerce orders
- Target only single product page
- Get category slug of the Parent category of a Product
- How to fetch courses in all languages in WordPress?
- How to distinguish pages created by woocommerce?
- Disaply products from category
- Show code only on WooCommerce Pages
- Woocommerce – custom post type of checkout page
- Wp_query WooCommerce products
- How to get only post=’product’
- What is the use of to_ping and pinged column?
- Prevent Authors from viewing each others Posts
- Listen to Post action
- Export WordPress Posts and Meta Information in CSV format
- How to add post count to wp_nav_menu?
- Posting From Apple Aperture?
- how to show all post in my page-grid.php template page
- How to add padding between posts
- eBooks download website, page or post?
- Remove whitespace at the end of posts?
- Add few specific post ids to wp_query
- generate unique slug while inserting post
- Add filter-by-tag in the all posts admin console page
- Can I hide a specific post from latest posts page?
- get posts and postmetas in assoc array
- user contributed content as custom post types
- Is 30 posts/sec considered slow for wp_delete_post?
- How to load a different header based on post format?
- Latest 5 posts (custom post type), each post different CSS
- Add scripts on custom post add/edit pages Not Working
- Getting current post ID in functions.php
- Understand post type
- Getting content from a single *page* of a post
- How can I show wordpress posts based on author?
- Remove certain post-formats from showing in blog?
- Avoid duplicate post from same Taxonomy
- Email Post Attachment on wp_insert_post Action
- Can I divide the pages into categories?
- WordPress Retrieve Post by Title
- How to include the latest post of a specific category on a matching page
- API endpoint to get most-read and popular posts
- Is it possible to run wp_kses on all posts?
- How to bulk-untag multiple posts?
- Responsive images with custom image size
- display-posts shortcode attributes have no effect
- Take a received feedback item, turn it into a post
- plugin to post from admin to flickr [closed]
- Is there a way to specify an extra class for a post or page with no title?
- store posts_id of category into a varable?
- Get post meta retrieving wrong value
- How safe is it to delete old posts edits to save database space?
- If contributor has published 2 or more posts then show otherwise hide
- How to Assign / Move all Deleted post to a category
- Display a mixed list of posts and media
- Using wp-cli and delete everypost first image
- Assigning Two Different Post Dates For Single Post
- Show posts by quarter
- Inserting an example of the last 3 post on to the homepage
- Make ‘blog’ page show content as well as posts underneath it
- Cant’ Grab WordPress Built-in Posts Through Loop
- Sidebar limiting to 10 posts?
- Attachment image single page
- Display content between two dates?
- How to associate a custom taxonomy to a post multiple times
- Post date automatically +100 years into the future
- Can I show category name in url for only one of my categories?
- How to let a user create a post by submitting a POST form?
- How to fix wordpress blog post error? Can anyone help to fix this issue?
- Query prints posts without specific categories
- migrate only recent posts
- Disable pagination in posts and pages
- wpautop filter off for pages but on for posts
- post categories – how to show only categories with a specific parent id
- Creating a “category” of featured posts
- How do I create a ‘selection’ criteria list’ that will then dictate which posts are generated when the user presses search?
- Post URL duplication adds numerical value
- Is it possible to display QUICK EDIT as default for all posts in wp-admin/edit.php page?
- get “read more” with custom DB query like you would with WP Query
- Create custom URL with different levels
- some posts being displayed as pages
- Body text disappearing in random posts
- Get part of a page url
- Add default content to post (for specific category)
- Displaying posts on Homepage
- Adding a time stamp on post view
- Where are my posts linked to? I keep getting a Not Found Error, and I have no single.php page
- The post order is different for logged-in and non-logged-in users? [closed]
- Display one post randomly from category on home page
- Change a div background color on Post ID
- How to show all Posts Image, Title and 3 line description on main page?
- CSS code for “inserting a custom post divider” after each post