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

Check if meta key value already exists

Just do a query with WP_Query using the Custom Field parameters (meta_query) to look for posts with the meta key and the value – exemplary code: // args to query for your key $args = array( ‘post_type’ => ‘your_post_type’, ‘meta_query’ => array( array( ‘key’ => ‘videoid’, ‘value’ => $new_posts_videoid // for example: ‘111’ ) ), … Read more

Categories metabox Tags metabox, post-meta

Permalinks using event date (year & month) instead of publication date

The short answer: you need to modify the query for your single event post to include the metadata, so only posts with matching name, year, and month will be returned. I’ll show you the complete code I used to test this. I made a few changes to your code and simplified a few things, so … Read more

Categories custom-post-types Tags custom-post-types, date, permalinks, post-meta, rewrite-rules

How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?

When you save an array as post meta, WordPress will serialize it to a string and save that string. Let’s take a simple array: array ( 1 => array ( ‘url’ => “https://wordpress.stackexchange.com/”, ‘title’ => ‘Home’ ), 3 => array ( ‘url’ => ‘http://wordpress.stackexchange.com/’, ‘title’ => ‘WordPress Stack Exchange’ ), 4 => array ( ‘url’ … Read more

Categories post-meta Tags post-meta

Custom query with category exclusion and post-meta “whitelist”

Is it possible to do a custom query and convert it to a standard WP_Query object? Yes. You can do something like… $post_ids = $wpdb->get_col(“SELECT ID FROM {$wpdb->posts} WHERE ….”); $posts_qry = new WP_Query(array(‘post__in’=> $posts_ids,’orderby’ => ‘post__in’)); The second query will preserve the order of results from the first. I am fairly sure that you … Read more

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

How to enable users to down-vote in this simple voting counter (that uses the post meta)?

You will have to make a second button for down voting. Give the upvote button a class of up and the down vote button a class of down. jQuery <?php wp_enqueue_script( ‘jquery’ ) ?> <?php wp_head(); ?> <script type=”text/javascript”> jQuery(document).ready(function() { jQuery(“.vote a.up”).click( function() { var some = jQuery(this); var thepost = jQuery(this).attr(“post”); var theuser … Read more

Categories plugin-development Tags ajax, plugin-development, post-meta

Multi-line captions on attachments

I don’t think you can do that, however you can implement this code in your functions file to at least allow for line breaks in single image captions Note: doesn’t work for gallery images (I am trying to find a way to make it work in galleries) /* ********************************************* Function to allow multi-line photo captions. … Read more

Categories attachments Tags attachments, captions, post-meta

What is an efficient way to query based on post_meta?

I’d like to see what the actual generated SQL is that WP_Query is using, but for now. ( You can use http://wordpress.org/extend/plugins/debug-bar/ to easily view the SQL query ) Queries ordered by ‘random’ are inefficient. If you don’t need that remove it. If you do need a random order, consider removing it anyway and using … Read more

Categories wp-query Tags database, meta-query, post-meta, sql, wp-query

Media manager multiple selection

I’ve edited your code a little and the alert() runs for each selected item. Note that in your code you execute a return too early that make the code bellow don’t run after the first run. Also, you use the same name for a function and for a string var, which is not very appropiate. … Read more

Categories jQuery Tags file-manager, jquery, media, media-modal, post-meta

Change meta tags programatically

I think you need to do the add_action( ‘wp_head’, ‘add_meta_tags’ , 10 ); in your functions.php instead of the template to get the function called. And it adds it then everywhere where you have wp_head(). So if you want to only call it content-share.php you need some conditioning logic like if (is_page_template(‘page-templates/content-share.php’)) { add_action( ‘wp_head’, … Read more

Categories functions Tags actions, facebook, functions, post-meta, wp-head

Add post meta based on another post meta value before publish post

The solution is using added_post_meta and updated_post_meta hook . Here is the working code . add_action( ‘added_post_meta’, ‘add_custom_field_automatically’, 10, 4 ); add_action( ‘updated_post_meta’, ‘add_custom_field_automatically’, 10, 4 ); function add_custom_field_automatically( $meta_id, $post_id, $meta_key, $meta_value ) { if ( ‘_my_meta_key’ == $meta_key ) { add_post_meta($post_id, ‘_my_new_meta_key’, $meta_value.’to something new’, true); } }

Categories post-meta Tags post-meta, save-post
Older posts
Newer posts
← Previous Page1 … Page183 Page184 Page185 … 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