Is it possible to update the dataset using update_post_meta

You don’t need your second foreach loop. foreach( $_POST[‘wt_set’] as $name => $val ){ update_post_meta( $post_id, $name, $val ); } What’s happening is with your second foreach is each entry is being processed individually and set as the post meta, so as it’s looping through it’s running update_post_meta( $post_id, $name, XXX ); then update_post_meta( $post_id, … Read more

Gutenberg add a custom metabox to default blocks

Using filters we can modify the props and attributes of blocks. First we extend the attributes to include the new attribute: const { addFilter } = wp.hooks; // Register/add the new attribute. const addExtraAttribute = props => { const attributes = { …props.attributes, extra_attribute: { type: “string”, default: “default_value” } }; return { …props, attributes … Read more

Create multiple taxonomies with custom fields values on the fly when creating new posts

This is the code I use to insert a list of taxonomy terms in a dedicated plugin category. On can also directly add the terms to the main post category. // ************** Add taxonomy $taxonomy_term = “my_term”; $taxonomy_category = “my_taxonomy_category”; if (null !==(get_the_ID())) { if ( taxonomy_exists( $taxonomy_category ) ){ // if the tag doesn’t … Read more

Filter custom post type admin list by custom meta column, where the column is another custom posts meta value

One solution may be to get all position ids, where project id matches and compare them with the ‘OR’ comparer. $position_ids = get_positions_in_project($project_id); foreach ($position_ids as $id) { $meta_query[] = array( ‘key’ => ‘feedback_position_relation’, ‘value’ => $id, ‘compare’ => ‘=’, ); } $meta_query[‘relation’] = ‘OR’; $query->set(‘meta_query’, $meta_query) But the problem with this is, that meta … Read more

Sort categories by custom field in WordPress admin

For some reason the add_action( ‘pre_get_posts’, ‘category_custom_orderby’ ); hook isn’t working. Yes, and it’s because on the Categories admin page (where you can see the Categories list table), the list table uses WP_Term_Query and not WP_Query, hence the above hook (pre_get_posts) is not fired. So instead of the above add_action(), try using the parse_term_query hook … Read more