Articles of custom field

create custom meta box with default value

I am creating a custom admin panel where the admin can choose between 3 layout using radio buttons. Everything works perfectly except when admin creates a new page there isn’t default option. I solved this by using: if ($layout == “”) { $layout = “layout_1”; } I hope someone can help me with a better […]

Can I save post meta programatically without setting metaboxes?

I want to know if is it required to have metaboxes set to save post meta into a custom post type. I have a couple of pages where I save metadata into a post programatically, using add_post_meta, but I wanted to know if I can save data that is not set using add_meta_box. Is it […]

After ajax image is outside the `<a>` tag

I am loading some content via AJAX, and basically I have this line: $storage .= ‘<a href=’.get_permalink($id).’><img src=”‘.$image[‘url’].'” /></a>’; Which gets rendered as: <a href=”//localhost:3000/story/story-title-wide”></a><img src=”//localhost:3000/wp-content/uploads/2016/05/story_wide.png”> As you can see the <a> is empty and the img is rendered afterwards instead of being rendered inside the <a>. The whole AJAX function: add_action(‘wp_ajax_nopriv_GET_MORE_STORIES’, ‘get_more_stories’); add_action(‘wp_ajax_GET_MORE_STORIES’, ‘get_more_stories’); […]

Copy custom field value to post title

I used the code found here. However, that does not update the title field until you open the post and hit Update button both via the back and front-end. I tried changing “save-post” hook with “edit_post”, “publish_artist” and “wp_insert_post_data” but still get the same result. Below is the code I used upon using “wp_insert_post_data” hook. […]

TinyMCE custom button retrieve value from custom field

I’m creating a plugin that adds a custom button to the default TinyMCE editor in WordPress admin. The following code builds this simple plugin mkay-tinymce-extra-button.php function mkay_enqueue_plugin_script( $plugin_array ){ $plugin_array[‘subscriptionPlugin’] = plugin_dir_url( __FILE__ ) . ‘mkay-tinymce-extra-buttons.js’; return $plugin_array; } add_filter( ‘mce_external_plugins’, ‘mkay_enqueue_plugin_script’ ); function mkay_register_buttons_editor( $buttons ){ array_push( $buttons, ‘subscription’ ); return $buttons; } add_filter( […]

Display Repeatable Meta Box Content

I’m using the following repeatable meta box code in my functions.php: /** * Repeatable Custom Fields in a Metabox * Author: Helen Hou-Sandi * * From a bespoke system, so currently not modular – will fix soon * Note that this particular metadata is saved as one multidimensional array (serialized) */ function hhs_get_sample_options() { $options […]

Accessing Custom Fields on Pages

I’m wondering how to get at custom field information attached to a page, not a post. Using get_post_meta seems like the right idea, but I don’t know how to tell the function to look at page ids and not post ids. Also it’s no clear to me if this function can work outside the loop. […]

how can I show name and value of Custom Fields together?

I know how to show name and value of all Custom Fields <?php the_meta(); ?> and I know how to show one Custom Field value <?php echo get_post_meta($post->ID, “yourkey”, false); ?> But how to show name and value of one particularly Custom Field.

How to make custom comment fields required

In wordpress theme i create a custom field with name city in comments form. Its showing and save data well. But problem is that its save the value while its empty. Need Its show error when submit form with empty city field. i add function for validations but not working. How to make city comment […]

How to display custom fields from a plugin

I use a plugin, WooCommerce Simple Auctions. It has a list of custom fields, which I want to display their values. I got told by the support that I should use var_dump(), which I did, and it returned a null string. I use a child theme for this. I want it to display in the […]