New answers tagged

1

Are you outputting the saved data to the edit post page before saving the post? If not you may be getting a empty $_POST['collection-topics'] data and then saving empty or null data. I would do a check before doing add_post_meta() if ( empty($_POST['collection-topics']) ) return;


0

Storing of your own meta fields is typically a custom process, more so if you are using a third party framework. Technically it's possible, but clunky: Hooking into save_post would allow you to check if meta is added to it If so you can immediately query for previous (if any) post that had it and unset the meta for it However I concur with the comment ...


1

This is how meta_key/_values work. How you store your values is case sensitive. Example meta_key = 'foo' and meta_value = 'Bar' Would return the result you are looking for: $posts = new WP_Query( 'post_type=post&meta_key=foo&meta_value=Bar' ); Would not return the result you are looking for: $posts = new WP_Query( 'post_type=post&meta_key=...


1

While you can't edit the dropdown list, you can achieve what you want as long as you are able to edit your theme or if your theme uses the standard the_author() template tag. To recast your question, you want: Editor's names to show as Name + nickname + surname Other names to show as nickname No-one to be able to change this except Admins I'm assuming ...


0

Use wp_kses with an empty array as the allowed_html parameter. This will sanitize the string without removing line breaks and should pass most coding standards


-1

<?php $args = array( 'post_type' => 'product', /* your Custom post slag */ 'meta_key' => '_wla_homepage_slider_checkbox', 'meta_value' => 'on', 'posts_per_page' => 15, 'no_found_rows' => true ); $query= new WP_Query( $args ); ?>


0

Do a search for anywhere you're using get_post_meta in your page templates like page.php or single.php all the way down the line for whatever you are including in your page. You can also hook get_{$meta_type}_metadata and output the key/value pairs passing through which would tell you when a page is requesting metadata.


1

In general the answer is yes and the web is full of good tutorials that would do a better job than I can here.


1

Here's the solution update wp_postmeta set meta_key = 'theme2035_embed' where meta_key = 'video'


1

Sadly the stock wordpress doesn't give much more help with custom fields. I'd recommend using the advanced custom fields plugin. https://wordpress.org/plugins/advanced-custom-fields/ You can set the name when creating a field and match it to what you've been using and it should work retroactively on old posts and content as well.


0

I use update_user_meta to update the fields. You can add this in functions.php of your child theme. function save_extra_user_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) { return false; } update_user_meta( $user_id, 'telephone', $_POST['telephone'] ); } add_action( 'personal_options_update', '...


0

Since you can't really do this, I would recommend using the Theme My Login plugin, a very simple member plugin which will just create "log-in", "log-out" and "profile" pages that will fit the customization of your theme. You'll be able to change the order of the fields as you wish in a distinct file that you can add in your child theme, so you won't have any ...


1

You should always use update_post_meta() function because if the term doesn't exist it will make a call to the add_post_meta() automatically. The same goes for update_user_meta(). Example if you want to add the meta "City" but you don't have it in the db you simply make a update_post_meta($city) and in $city you need the post_id and the new value for city....


0

The way I solved this, was to set up a custom post type set up for each of the default images I wanted, then pulled in the post with the featured image associated with each.


0

You do not verify the nonce correctly. Try this, it should work: //1. verifies meta box nonce (to prevent CSRF attacks) if( !isset( $_POST['work_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['work_meta_box_nonce'], basename( __FILE__ ) ) ){ return; } For more info on wp_verify_nonce see here.


0

Create Custom Post Type function create_product() { $labels = array( 'name' => _x( 'Product', 'post type general name', 'stacy' ), 'singular_name' => _x( 'product', 'post type singular name', 'stacy' ), 'menu_name' => _x( 'Products', 'admin menu', 'stacy' ), 'name_admin_bar' => _x( 'Product', '...


0

Demo - Setup Here's a demo how we could control the display of comment fields and their order: Let's create a custom class: $mycf = new MyCommentFields; Then we define our extra fields: $myfields = []; $myfields['myaddress'] = sprintf( '<p class="comment-form-myaddress"> <label for="myaddress">%s <span class="required">*&...


0

You can use the following function to update custom field value for user update_user_meta( $user_id, $meta_key, $meta_value, $prev_value ); For more information. Please visit


0

$val = get_post_meta( get_the_ID(), 'meta_data_name', true ); echo $val; You can replace get_the_ID() with the ID of the post you are getting the meta from. You could possible team this with: $frontpage_id = get_option('page_on_front'); to get the homepage ID. Not sure if this would be friendly with multisite though. the_field() is an Advanced Custom ...


0

First, you don't need the <form> tags; meta boxes are already rendered inside the post edit form. Second, if a checkbox is not checked it is not sent, so isset( $_POST['checkbox_name'] ) return false and the custom field that stores the value of the checkbox is not update correctly. I've tested this code with standard post type and it works, it must ...


0

Try to change 'orderby' => 'meta_value','meta_key' => 'event-date-start'


-2

Pay for the ACF Pro version to enable flexible fields (which is basically the function I wanted to have) or use an alternative WP plugin that has the feature for free, such as Carbon Fields or Piklist. If you want to display PHP in the textboxes, although creating a security vulnerability, you could use Shortcodes. For instance, to display a field in your ...


0

There was a flexible content container with the content inside that required an extra loop to reach the content. This helped (https://support.advancedcustomfields.com/forums/topic/get-another-pages-flexible-content/) <ul class="rslides_m16 rslides"> <?php if( have_rows('page_modules', $postID) ): ...


0

You can't do this by default, but you can write a query to do it within your theme. It could be a security risk to allow any field to be entered in the URL, so you'll need to explicitly detect those that you are wanting. In your functions.php, you could add something like this (untested!): add_action( 'pre_get_posts', '...


1

You've almost got it - it's just a problem with logic. What you're basically saying is "get posts that don't have this meta key, or where this meta key isn't equal to 'dhaka'". The problem is, posts without that meta key at all... also aren't equal to 'dhaka', so therefore they match! You can fix this with a nested meta_query, using an AND relation, to ...


0

I'm not entirely 100% on the order you are looking to achieve, but I think you need to spend a little more time with the documentation for WP_Query. An orderby array takes the name of a column in the wp_posts table OR meta_value or meta_value_num as the key, not the name of the custom field key (custom_key in your case). The actual name of the custom field ...


0

Okay! Finally, I was able to make it work. Below is the complete working code. add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 2 ); // Grabs the inserted post data so you can modify it. function modify_post_title( $data ) { if($data['post_type'] == 'artist' && isset($_POST['acf']['field_573676a95d920'])) { // If the actual field ...


0

I always find it way less confusing to get the results from one table and loop them rather than to try to join them like that... eg. global $wpdb; $query = "SELECT post_id FROM wp_postmeta WHERE meta_key='fake_author' AND meta_value='11111'"; $results = $wpdb->get_results($query); foreach ($results as $result) { $query = "UPDATE wp_posts SET ...


1

Here's one way to inject the custom field as the featured image caption with help of the post_thumbnail_html filter: add_filter( 'post_thumbnail_html', function( $html, $post_id ) { if( $html && $caption = get_post_meta( $post_id, 'wpcf-bildunterschrift', true ) ) $html .= sprintf( '<p>%s</p>', sanitize_text_field( $caption ) ...


3

numberposts doesn't exist for WP_Query instead use "posts_per_page" => 1


0

You can use TGM Plugin Activation library to let the user know about required and recommended plguins that your theme depends on. Automatically installing plugins is not a better choice instead let the users know that X plugin should be installed and activated in order for the theme to work properly. If your theme requires a plugin without which it gives ...



Top 50 recent answers are included