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

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

How to update single value in multi dimensional Post Meta?

You may need to unserialize the data to get the array and loop through it thus: $userid = 832; // or 1540 $votes = get_post_meta($postid,’voter’); $votes = maybe_unserialize($votes); if (is_array($votes)) { // votes is the array, key is numeric index, vote is subarray foreach ($votes as $key => $vote) { // subarray values are in … Read more

Categories PHP Tags array, meta-query, php, post-meta

Should I sanitize custom post meta if it is going to be escaped later?

Short Answer: If you have properly validated the data, then sanitization can be made optional. Longer Answer User-supplied data and data from unknown/external sources should always be treated as untrusted even in the case where the user was actually yourself, so yes, we should always validate and/or sanitize such data. And therefore, no, please do … Read more

Categories post-meta Tags post-meta, sanitization

importing data from non-wordpress mysql db

you need to get the ID back from your post insertion and use that with add_post_meta: $post_id = wp_insert_post($post); add_post_meta($post_id, ‘thumbnail’, $yourvalue, true);

Categories custom-field Tags custom-field, database, import, mysql, post-meta
Older posts
Newer posts
← Previous Page1 … Page185 Page186 Page187 … Page204 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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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