paste this code in you theme’s function.php file
//get all categorie ID's in to array
$args = array( 'child_of' => 3678); // Parent category ID
$categories = get_categories( $args );
$cat_array = array();
foreach ($categories as $category) {
$cat_array[] = $category->term_id;
}
$Query_args = array(
'category__in' => $cat_array,
'post_type' => 'YOUR_POST_TYPE_NAME'
);
$new_query = new WP_Query();
$new_query->query($Query_args);
if ($new_query->have_posts()){
while ($new_query->have_posts()){
$new_query->the_post();
foreach((get_the_category()) as $category) {
if (in_array($category->cat_ID,$cat_array)){
update_post_meta($post_id, 'price', $category->cat_name);
}
}
}
}
replace “Parent category ID” with price category ID and then save that file
after that remove this code and save again.
Related Posts:
- importing data from non-wordpress mysql db
- Query meta field using between
- Move value of one custom field to another
- Get multiple custom field values in a $wpdb query [duplicate]
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- little help with a mySQL query to wp database
- Importing users to Buddypress with custom fields
- MySQL query to set wp_postmeta using term_taxonomy_id value
- MySQL Query that looks for post with Custom Field, then changes Category
- Unique Post Meta Values
- Add custom field to all posts in specific post_type
- UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
- Importing WordPress Posts With Custom Meta Data As CSV Files Through PHPMyAdmin
- Inserting data into MagicFields using mysql queries
- If I update WordPress my custom data will be deleted from the wp_users table?
- Update post meta data (custom field) by post link
- Help setting up a sql query
- wpdb function insert doesn’t work
- How to improve my non-unique metadata MySQL entries?
- Delete a custom field in mysql for all posts with specific category id
- use mysql to replace one custom field value with another custom field value
- Copy url from post_content to custom field
- Convert many posts from having a specific meta_key to use a post_format
- Custom Search, MySql Query Gone Wrong?
- Can running a WP-Cron to update_post_meta cause performance issues?
- WP_Query – Order results by meta value
- Difference between meta keys with _ and without _ [duplicate]
- Orderby meta_value only returns posts that have existing meta_key
- Can I query custom meta data through WP_Query
- Add custom objects/entities to WordPress
- Change behavior of “Insert into Post” based on attachment metadata
- Sort posts by custom field numeric value using dropdown
- How to position a custom field before the editor
- How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
- Is there a way to do multiple ordering on a multiple meta_query?
- searching in custom meta field
- How to add upload field in a custom taxonomy?
- Display thumbnail from custom field
- Store JSON in a custom field
- Custom contact form 7 select with custom values [closed]
- Setting orderby to a custom field using pre_get_posts
- Add WYSIWYG to Image Description field
- Adding Custom Fields to Search
- How to Display Custom Meta Box only on Specific Page IDs
- Get custom field label
- Show ACF fields only on certain page in the backend
- How make a custom search on backend in WordPress without plugin?
- Create Multiple File Upload Metabox in WordPress
- WP_User_Query pulling ACF to loop
- how to put a custom field value in variable
- How to add the image URL from an external RSS feed and insert into a custom field?
- My custom backend codes shows up when i try to view my website
- Advanced Custom Fields dynamic update_field
- Custom Profile Fields move from BBpress to BuddyPress
- How can I output a list of values for a custom field, and posts with those values?
- I need a “Choose from existing content” popin
- For homepage images (for small business website), is it better to use custom fields or post_thumbnail?
- Avoiding ACF get_field and returning to core WordPress function
- Display custom field value part by part?
- How can I hide custom field from users used for caching response from external api?
- WordPress custom fields feature is missing in my installation
- Print Posts if Custom Field Value Date equal or greater than Today Date
- Is it possible to populate a custom field with content from a page
- Save all custom field data into one “master” custom field
- Convert all dates stored in custom field
- How to put forward a blog post
- Plugin or shortcode for ISBN number?
- HM CMB: Role Select
- Display latest post depending on Meta Box content
- WP-eComerce Advance Meta Tag data in descending order [closed]
- Custom Query Fields – Altering Meta Value
- Replacing custom field with shortcode
- WPAlchemy issue when using 2 select menus with the same values inside a repeating group
- show a specific metabox dependent on the page template
- excluding posts by an ACF field in pagination
- Search & column order by meta value in admin
- Is the use of many custom field not good for server?
- How can I ‘check’ the “custom fields” box from the Screen Options?
- Very large list of options for BuddyPress profile fields
- Can you generate a featured image from two images from custom fields?
- Sql Update CPT from publish to draft and particular custom field
- How to get all wp_posts in wordpress fetched from database
- Search fails when using the radio buttons
- automatically add custom fields to post title
- Custom Fields Permalink Plugin not observing hyphens
- will wp_insert_post write a new custom field to the database?
- How to repeate custom field group with bulk image field
- Extra text’n’image field in a page
- Order a query by meta_value and then by post_date
- custom field functionality
- Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
- Decouple page name from page title
- Custom Field add markup to line breaks
- Use Metabox to enter Post Title
- Include custom fields into the content of a regular page
- Bypassing a Form Options
- How to implement jquery-ui autocomplete into custom fields?
- i want to send email on custom post field (job_status == 2) but it is not working
- How to create a searchable database with a single-field search box at the front end? [closed]
- Add custom fields to specific menus