New answers tagged

0

This is definitely possible. I'm going to assume that you're using a theme that you didn't write yourself, so best practice will be to create a child theme with your current theme as the parent (called 'template' in the thild theme). Next, you'll want to find the custom post type and its meta boxes in the parent theme. The first file you'll want to check is ...


0

Directly accessing PHP files is not really how WordPress works. You currently have your code in a random PHP file that has no connection to WordPress. It's probably throwing a Fatal error (Call to undefined function), which is why the next line doesn't get executed. You said this code is in your theme, so I would start by putting that code in functions.php. ...


0

Here's an example of how to get the meta and set it as the post content. You would need to add all the meta keys to the $meta_fields array. Obviously test this locally before running in production because it will overwrite whatever is currently in the post content. function migrate_post_data() { // Add all the meta keys you want to migrate to this ...


0

In your code this in the condition where you decide when to apply the meta query condition: if($query->is_main_query()) { Therefore if the conditions inside there are working sometimes and not others, it means that condition is true when it's working and not when it's not. The solution to this is dependent on all the code running on your site, but first ...


0

it was completely my bad. I am using this plugin and I updated my functions.php file but the plugin wasn't activated although I thought it had been. Extension is here & it works in 5.4.2 with Gutenberg blocks if anybody is intereested: https://github.com/jchristopher/attachments


1

EDIT: Original answer was inaccurate as you can do this with wp_update_post and the meta_input field As per the updated question and comments this is possible with wp_update_post (or wp_insert_post for a new record) using the meta_input key on the array, e.g.: $metaValues = array( 'key1' => 'value1', 'key2' => 'value2', // ... as many ...


0

You can avoid needing to test for the post type in the save_post action by using save_post_{post_type} E.g. add_action( 'save_post_portfolio', ..... Where portfolio is the post type being saved. Using save_post will run your code for all posts types unless explicitly checked.


0

add_action( 'save_post', ... and test if your post type is tour custom post type.


1

By doing a SHOW CREATE TABLE on wp_postmeta, I got the structure of that table which included this: PRIMARY KEY (`meta_id`), So the key that MySQL can do the 'insert or update' on is the meta_id, which you're not providing. Therefore in your query, it will always be added as a new row. EDIT: The docs for INSERT ON DUPLICATE UPDATE say that it looks at ...


0

The following example is adding a meta box to the post edit screen and the wporg_cpt edit screen. function wporg_add_custom_box() { $screens = ['post', 'wporg_cpt']; foreach ($screens as $screen) { add_meta_box( 'wporg_box_id', // Unique ID 'Custom Meta Box Title', // Box title 'wporg_custom_box_html', ...


1

This is just a basic php array question - not a WP question. function unique_authors ( $authors ) { $newArray = array(); foreach( $authors as $item ) { $itemArray = explode( ", ", $item ); $newArray = array_merge($newArray, $itemArray); } $newArray = array_unique($newArray); return $newArray; } $authors = ...


0

Apart from any other errors that might be in your code that some others have pointed out, I've found that accessing attributes defined as "meta" from the save function has issues. I've posted my own question about it here. and a bug report about it here. Essentially, while the documentation says "meta attributes can be read and written by a ...


Top 50 recent answers are included