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

When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?

When multiple meta values are used for same meta key, WordPress store the values in different database rows. So every array, is stored in one row. Initial Data Let’s assume you have an array like this: $family = [ ‘father’ => [ ‘John’, ‘Doe’, 40 ], ‘mother’ => [ ‘Jane’, ‘White’, 39 ], ‘child_1’ => … Read more

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

Getting attachments by meta value

I’ve spent hours of research and found the solution a few minutes after writing this question: $args = array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘inherit’, <<– IMPORTANT ‘meta_query’ => array( array( ‘key’ => ‘medientyp’, ‘value’ => ‘Video’ ) ) ); $query = new WP_Query($args);

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

Meta compare with date (stored as string) not working

Introducing STR_TO_DATE MySQL has a STR_TO_DATE function that you could leverage for the scope. To use it you need to filter the WHERE clause of a WP_Query, probably using posts_where filter. That function allows to format a column value as a date by using a specific format. By default, WordPress uses the CAST MySQL function … Read more

Categories post-meta Tags meta-query, post-meta

Content hooks vs User hooks

It depends on what exact action you are using, and what the purpose of that action is. For the update actions, for example, there should always be hooks that are triggered before doing the change (so that you may change or prevent it), and hooks that are triggered after the change has been completed (so … Read more

Categories post-meta Tags actions, post-meta, user-meta

Can I count the number of users matching a value in a multiple value key?

If you are working with serialized data as your meta_value, that sucks, as Pieter suggested, it’s best not to. However if there is no way around the serialization problem then I wonder if a meta_query using a compare value of LIKE might help… Example: //psuedo serialized data… (e.g. value of meta_key = fruits_user_like) //a:4:{i:0;s:5:”apple”;i:1;s:6:”orange”;i:2;s:6:”banana”;i:3;s:31:”serialized_data_sucks_sometimes”;} $users … Read more

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

Export WordPress Posts and Meta Information in CSV format

What is the SQL query you are using? What are more details of the export and end format you need? The obvious things are 1) http://wordpress.org/extend/plugins/navayan-csv-export/ “Navayan CSV Export is a wordpress plugin to export all your table data in CSV (Comma Separate Value) format.” and 2), exporting with phpmyadmin – the database utility – … Read more

Categories posts Tags post-meta, posts, sql

update_post_meta not saving when value is zero

update_post_meta() calls update_metadata which begins with this line: if ( !$meta_type || !$meta_key ) return false; I wrote a simple test (with a lot of cut & paste) to see how string values of 0 are evaluated (instead of looking it up in the PHP manual): <?php $meta_key = (string) 0; if ( ! $meta_key … Read more

Categories post-meta Tags post-meta

What is the most efficient way of querying posts based on visits and date for current day?

I think that you can improve performance saving view information in one single option instead in post meta applying the filter date on saving instead of on retrieving create the markup and save in a transient instead of saving the query (fragment caching) Rough implementation in a class class PopularPosts { const OPT = ‘myplugin_popular_posts’; … Read more

Categories wp-query Tags filters, performance, post-meta, query, wp-query

advanced custom fields update_field for field type: Taxonomy

I do need to add both post_meta: add_post_meta( $insert_q_key_id, ‘q_key_type’, (int)$q_key_type ); // Q Key Type And for ACF: update_field( “field_52c737a413e07″, (int)$q_key_type, $insert_q_key_id ); // Q Key Type And the rest of the answer “should” be covered by wp_set_object_terms: wp_set_object_terms( $insert_q_key_id, (int)$q_key_type, ‘q_key_type’, true ); However, this function is not fully available at the point … Read more

Categories post-meta Tags advanced-custom-fields, post-meta, wp-insert-post

Dealing with Many Meta Values, 30+

You are facing an XY Problem. The only reason to save meta values each as a single row, would be if you need them to be searchable. If you need specific sanitization rules, use either filter_var_array() or sanitize the values, then build the array and finally save the value. Gist with a comprehensive filter_var_array() example … Read more

Categories Database Tags customization, database, meta-value, post-meta, search
Older posts
Newer posts
← Previous Page1 … Page194 Page195 Page196 … 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