New answers tagged

0

I found an older post showing what I was missing from my code, so it seems like I didn't do a good enough search to begin with. For anyone wondering I was missing 'compare' => 'LIKE' from the query, so the code would look like this: $args_post = array('post_type' => 'release', 'orderby' => '_custom', 'order' => 'ASC', 'posts_per_page' => -1, ...


0

You would want to use the wp_enqueue_scripts action, and within there, instead of custom_field you would use get_post_meta, like this: function wpse217823_enqueue_per_custom_field(){ global $post; $layout = get_post_meta( $post->ID, 'layout', true ); if( $layout == ... ){ wp_enqueue_style( 'my-custom-style-here' ); } } ...


0

stick with cmb2 -- there is another method of displaying and then saving meta data, but it's a PAIN and loads your functions file. the plugin pretty much has no effect on the front end of the site -- it'll also make your meta boxes a lot cleaner and consistent-looking


0

it was just missing $upload_dir['path'] . "/" . $upload_file_name in $uploaded_file['attach_id'] = wp_insert_attachment($attachment, $upload_dir['path'] . "/" . $upload_file_name); require_once(ABSPATH . 'wp-admin/includes/image.php'); //Generate the metadata for the attachment, and update the database record. ...


2

I don't know what are you trying to achieve, but in my mind and opinion, you are definitely on the wrong track here. When a custom field is updated, nothing happens to the actual post object as custom fields aren't part of the WP_Post object. This means that no actions are triggered related to updating the post object itself, and therefor the post_modified ...


2

I would add another custom field that stores the update time. Then create an add_action function for update_post_meta to also save the timestamp at the same time you write to CUSTOMFIELD. The action triggered when adding a custom field is add_post_meta and when updating a custom field update_post_meta


3

You got it quite right, but with a few minor problems. First, please use a uniqe prefix for your functions and values - opacity or meta_save are quite generic and could be used by other authors. Second, the part where you get the meta opacity was missing, I added it for you - just retrieve the meta value from the current post. Third, I then created a ...


0

$posts is a reserved global variables which stores the value from the $posts property from the main query. By using $posts as a local variable, you are breaking the main query and the $posts global variable. This leads to unexpected output. You should use unique custom variables as local variables. You can solve your issue by changing $posts = get_posts( ...


4

This part of wp_insert_posts() gives it away: if ( ! empty( $postarr['meta_input'] ) ) { foreach ( $postarr['meta_input'] as $field => $value ) { update_post_meta( $post_ID, $field, $value ); } } where we see how the post meta fields are updated/added with update_post_meta(). Here's the inline description for ...


0

Have you tried putting the website URL into the website: What Wordpress Theme Is That? In addition to themes, that site displays plugin information and might just give you what you're looking for. The only plugin I've found that is similar to what you're describing is Wp-Appbox, but I'm not sure that it displays all of those details.


0

Now it works. Im very grateful to jgraup! All that I needed to change is to add $icon = $GLOBALS[$icon_var]; and change the $menu_list structure as jgraup recommended. Even there is no need for third-party changes. The final code: function sidebar_menu() { $menu_name = 'sidebar_pages'; if (($locations = get_nav_menu_locations()) && ...


0

You need to call global $variable; before you can use the variable. Try the code below instead for that line. // setup your global scope here global $icon_var; // set the new value in global scope $icon_var = get_post_meta($menu_item->ID, '_menu_item_custom', true); // then use the variable $menu_list .= "\t\t\t\t\t<li><a ...


0

Looks like it's possible to use a placeholder tag, the following is the PHP code using a _custom_link value of http://somelink.com/?ref=%%title%%. <?php // must be within the Loop $ref_slug = strtoupper(sanitize_title_with_dashes(get_the_title())); $regex = '(\%\%title\%\%)'; $ref_link = ( get_option('_custom_link') ) ? preg_replace( $regex, $ref_slug, ...


0

I believe you might be looking for this: Types Conditional FIelds Display And set each field to display only if not empty. Then you can set up an array of field labels... $fields['goal'] = 'My Goals: '; $fields['commitment'] = 'My Commitments :'; // ... and so on... Then loop through the fields to display them: foreach ($fields as $fieldkey => ...


1

There is no $post var local to your function, you need to use global $post first, or get_the_ID(). get_post_meta( get_the_ID(), '_cf_address', true );


3

Lets try the following: By default, all posts are returned regardless of comment_status, so lets run the main query as normal, that is, query all posts regardless of comment_status. We will also run a small, but very lean secondary query where we will get all posts which have a comment_status of closed which have a meta value of not yes The returned ...


0

I FINALLY figured it out. Phew. Answer is as follows: add_action( 'woocommerce_after_subcategory', 'my_add_cat_description', 12); function my_add_cat_description ($category) { $cat_id=$category->term_id; $prod_term=get_term($cat_id,'product_cat'); $term_meta = get_option( "taxonomy_$cat_id" ); echo '<div ...


1

This kind of meta query in WP_Query() or get_posts(): 'meta_query' => [ [ 'key' => 'score', 'value' => 50, 'type' => 'numeric', 'compare' => '>=', ], ], would generate the following SQL WHERE part: wp_postmeta.meta_key = 'score' AND CAST(wp_postmeta.meta_value AS SIGNED) >= '50' ...


2

The code you have provided is incomplete. Not sure if that is the only code you are using to achieve what you want. So, besides first code block which you have provided, bellow I am adding all rest of the code which is required to show the new field on backend in 'Order Details' box and make it editable through custom fields. Please note, in your second code ...


0

@Milo and @Howdy_McGee had the answer. I found the section I needed to modify in my functions.php file: case 'text': echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />', It was the value field that was getting truncated, so I passed it through ...


0

Check out the Meta Box plugin. This plugin can do everything you asked, plus it's very easy to work with and to extend. The codebase is simple and you can understand it easily. It also has many extensions which can help you to improve the appearance of the fields, re-organize them in groups and many things.


0

I found a function to get the Meta ID by Meta Key. This allowed me to correctly assign my $meta_ID variable, and now the delete ajax button works perfectly. No need to update the save function at all. function get_mid_by_key( $post_id, $meta_key ) { global $wpdb; $mid = $wpdb->get_var( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE ...


1

I've managed to get the following to work. Let me describe the technique so that you can decide whether or not to use it. the code uses two hooks, one fired just before the "side" meta boxes get placed, and another immediately after the "date/time" section in the publish meta box. the first hook (before) records the original post type, and then switches it ...


0

If you have a custom field (metadata) attached to a particular post, page or custom post type, you can do something like the following in your page template file: Example example-template-file.php <?php $sidebar_id = 'my-custom-sidebar-id'; $my_custom_meta_value = get_post_meta(get_the_ID(), 'my_custom_meta_key', true); if ( ...


0

This is pretty simple. So simple you need to make sure your guests don't insert bad code into you DB. So read up on Data Validation and Validating Sanitizing and Escaping User Data before you add anything to your site from a front-end form. Create a new page at /new-post Create a page template to target that page Setup AJAX actions Render your form inside ...


0

Sorry for a wrong answer. It is posted in other question. About your situation, Heroes seem like Category(Custom Taxonomy) Guides is a custom post (Custom post) About Heroes Type, it can be a subcategory of Heroes or you can create new custom taxonomy for it. In custom post, you just need to embed Heroes Types and Heroes if you have 2 different ...



Top 50 recent answers are included