How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?

I had a similar issue but couldn’t solved with the snippets on this thread. I had to order a query by: all ‘featured’ posts first (is_it_a_featured_etf) and by a numeric field (etf_aum) in DESC order after the featured ones. My solution: ‘meta_query’ => [ ‘relation’ => ‘OR’, ‘etf_aum’ => array( ‘key’ => ‘etf_aum’, ‘type’ => … Read more

SQL Query to copy value of a meta_key into another meta_key

First take a db backup! Second, in your question you mention the same meta_key, so made the following assumption: The meta_key you want to keep is “ehp_citation” The meta_key you want to change is “ehp_citation_old” * so make the correction accordingly Then you can try something like: UPDATE `wp_postmeta` AS pm_to_change LEFT JOIN `wp_postmeta` AS … 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

How can I change the admin search posts fields?

It is possible, but you’ll have to play a little bit with the actual query. As always, the furious posts_clauses filter comes to action: function wpse_alter_posts_search( $pieces ) { global $wpdb; // Make the input save $search_string = like_escape( $_GET[‘s’] ); // Your new WHERE clause $where = $wpdb->prepare( “$wpdb->postmeta.%s LIKE %s”, ‘YOUR_COLUMN’, // Should … Read more