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’
- Add custom Attachment Display Setting for images
- Rewriting post slug before post save
- Prevent Authors from viewing each others Posts
- Removing filter dropdown in posts table (in this case Yoast SEO)
- Is it possible to Schedule Attachments in WordPress?
- Export WordPress Posts and Meta Information in CSV format
- Getting the post_id in wp_ajax function
- Is post ID number always incremental n+
- How to know if get_posts() failed?
- Show related posts by category but ignore one category
- Replacing all attachment links in post with media file link
- post__in for get_posts with a dynamic array
- Check if post has children or not
- Change the default number of posts to show on mobile version
- I am trying to create a simple frontend form for posting
- Duplicate posts
- Post content being duplicated by the_content();
- How can I pass $post object to ‘save_post’ add_action?
- 1 column admin screen options – move submitdiv to bottom
- Single Post Navigation Within Each Category
- Disable REST API for a user ROLE
- Add confirmation popup on “Move to Trash”
- How to hide a post from ‘Recent Posts’ widget?
- How to get the latest posting time of archived pages in WordPress?
- Hide add new page button
- Insert posts in two tables
- get_next_post() not working
- Create a separate JS application for an individual post?
- post_parent is 0 when uploading new files
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- custom wordpress post loop – hide iframe content
- custom post type grid with content in lightbox [closed]
- Divide Loop Into Days & Categories
- Latest 5 posts (custom post type), each post different CSS
- Different template for posts of all subcategories of category
- Search for posts based on their url in the admin?
- “next_posts_link” and “previous_posts_link” display me NOTHING
- Can I set and show “important” post in my blog?
- Add scripts on custom post add/edit pages Not Working
- Add custom field automatically (add_post_meta) with value based on number of words of article
- Add Post Tags to Body Class
- WordPress – Hide posts in admin from user who did not write them
- How to access featured image?
- Mark menu item as current-menu-item for category
- Understanding and using metaboxes in posts
- How to display different number of posts
- previewing my posts on static page?
- How to retrieve the postID in a “image_send_to_editor” hook function?
- What part of template to edit to remove category name from the top of posts?
- Register post status, exclude from searches
- Post revisions disappeared (for some posts)
- Replace ‘published on date’ with ‘modified on date’ on Posts
- How to display category from recent posts?
- Set terms in a custom post
- Post-ID in url differs from $post->ID
- post categories
- Format the Layout of Images In The Edit Post Textarea?
- Choose whether to automatically add a taxonomy with the same name as the post
- Which WordPress hook fires after post content loaded?
- Move first half of posts to one parent page, second half to the other page
- Check if checkbox is marked on publish/update post
- How to create a submenu that will navigate through different posts in the same page
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Enable Comments Box On Custom Post Type
- Can I search posts and pages for css classes?
- minimum requirement to add posts via database
- Delete and perform a fresh install of WordPress
- Get Posts Under Custom Taxonomy
- Integrate OpenStreetMap on WordPress
- Need to remove duplication content on home page in wordpress theme
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- How to show full post?
- how do i add posts-page slug before posts slug in permalinks
- Admin – create custom post status and display above table
- Sort Posts Alphabetically Based on Specific Category (Divi)
- Inserting Media on New Post But Hides Previous Uploads for Editor/Contributor
- Undefined Function Fatal Error with Shortcode [closed]
- I have a website issue I am trying to resolve
- How to sort posts alphabetically based on a specific parent category
- Is it possible to use the_post 2 times in one loop
- Display related posts randomly that match “any” existing tags?