Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

post-meta

How to use Post Custom Metadata in Post Titles and Post Permalinks

This will do. The slug is saved on the wp_posts while custom fields are on the wp_posts_meta. If you want to make it like that you can use an action hook on save_post that will get the value of the custom fields and saves it as the post slug. Here is the code add_action(‘save_post’, ‘set_slug’); … Read more

Categories url-rewriting Tags post-meta, rewrite-rules, url-rewriting

Storing meta fields multiple times OR once with multi dimensional array?

I figured I’ll leave the meta values saving on multiple fields in the db, because I’ve been doing allot of pre_get_post query filtering. Some of the features in there are for searching/filtering on post meta data and would it start making things very difficult if I was to start saving values into doubly serialized values. … Read more

Categories custom-field Tags custom-field, post-meta

Restrict post edit/delete based on user ID and custom field

Through a lot more research and some trial and error, I figured out the correct code to use that will restrict a post from being edited based on the user ID AND a custom meta field. $user = get_current_user_id(); $super_users = array(1); The first two pieces of code within the function are important for restricting … Read more

Categories post-meta Tags actions, content-restriction, post-meta

Will a large postmeta table slow a site down?

“You should not write to the DB on front end requests” is the eleventh commandment. Your performance will deteriorate due to the writes locking down the table much more than the impact the size of the table will have. You should probably write such data in files instead of DB, or at least use a … Read more

Categories posts Tags post-meta, posts

Check if user already visited this post today

Note! This code was not tested! <?php function my_visitor_cookie($post_id) { if ( empty($post_id) ) { global $post; $post_id = $post->ID; } // get post meta $count = get_post_meta($post_id, ‘unique_post_visits’, true); // if there was no meta value if( empty($count) ) { $count = 0; } // check if cookie was already set (cookie name for … Read more

Categories PHP Tags cookies, php, post-meta

meta_query where value is equal to given value

You’re almost there — you just need to add the comparison to your meta query: $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘artist’, ‘value’ => $artistID, ‘compare’ => ‘=’ ) ) ); https://codex.wordpress.org/Class_Reference/WP_Meta_Query Remember to filter $artistID before accepting it in your query!

Categories wp-query Tags custom-field, post-meta, wp-query

What is the advantage of the wp_options design pattern?

The ability to store abstract key-value pairs without modifying the database structure is the reason. Without that, WordPress loses much of its flexibility. I can’t speak for others, but the single largest reason why I develop atop WordPress is its flexible nature. To quote one of your links above, Usually the reasoning behind doing what … Read more

Categories custom-field Tags custom-field, database, options, post-meta, wpdb

get_post_meta() unserialize issue – returns boolean(false)

I have managed to fix it at my own. I have used following code to update post meta update_post_meta($post_id, ‘tb_data’, base64_encode(serialize($new_value_array))); …and following code to get post meta $tb_meta = get_post_meta($post->ID, ‘tb_data’, true); $tb_meta_unserialized = unserialize(base64_decode($tb_meta)); I hope this will help someone.

Categories custom-field Tags custom-field, post-meta

How do I remove all the metaboxes for a custom post type?

If you want to hide all the metaboxes for all users, you can do that through the get_user_option_metaboxhidden_{cpt}, default_hidden_meta_boxes or the hidden_meta_boxes filter, according to the /wp-admin/includes/screen.php file. Here’s an example for the post post type: /** * Hide all metaboxes in the global $wp_meta_boxes */ add_filter( ‘hidden_meta_boxes’, function( $hidden, $screen, $use_defaults ) { global … Read more

Categories custom-post-types Tags custom-post-types, metabox, post-meta

How can merge two arrays values in one array and save in database

When you are saving the multidimensional array you can use this code: $product_img_path[$count][‘wpc_resize_thumb_img’] = $upload_dir[‘url’].”https://wordpress.stackexchange.com/”.$resize_img_name; $product_img_path[$count][‘wpc_resize_bid_img’] = $upload_dir[‘url’].”https://wordpress.stackexchange.com/”.$resize_big_img_name; update_post_meta($post->ID, ‘wpc_images’, $product_img_path); That way you can get multidimentional array like you want: Array ( [1] => Array ( [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-212×159.jpg [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_55-500×375.jpg ) [2] => Array ( [wpc_resize_thumb_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-212×141.jpg [wpc_resize_big_img] => http://localhost/test/wp-content/uploads/2015/06/Wallpaper_51-500×333.jpg ) … Read more

Categories PHP Tags array, php, post-meta
Older posts
Newer posts
← Previous Page1 … Page190 Page191 Page192 … Page203 Next →
+ More

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
Next Page »
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress