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

Conditionally Query Custom Post Types by Post Meta for Blog Home Page?

Hi @webcodeslinger: Here’s what a basic MySQL query for loading News and Events would look like (this is greatly simplified from what WordPress actually does): SELECT * FROM wp_posts WHERE post_type IN (‘news’,’events’) What you want instead is something like this (there are more performant ways to do this in MySQL but they are more … Read more

Categories custom-post-types Tags custom-post-types, post-meta, query-posts

Convert User ID’s to User Names in a single.php file

$thevoters_ids = get_post_meta( get_the_ID(), “thevoters”, true ); // get a comma separated list of ids $thevoters_ids = explode( ‘,’, $thevoters_ids ); // turn the list into an array foreach ( $thevoters_ids as $thevoter_id ) { // loop through the ids $thevoter = get_user_by( ‘id’, $thevoter_id ); // get the user object by id echo $thevoter->display_name; … Read more

Categories functions Tags functions, post-meta

Using date stored as custom field to filter posts displayed in admin

Second try: 😉 pre_get_posts runs AFTER parse_query(). parse_query() transforms ‘meta_key’ etc. into ‘meta_query’. get_posts() doesn’t seem to react on ‘meta_key’ etc. directly. So try adding $query->parse_query() after your $query->set() calls or use filter that runs before parse_query (edited, the parse_query() filter doesn’t work, either – it runs too late). Edit: to do the switch: function … Read more

Categories custom-post-types Tags custom-post-types, date-time, post-meta

Trigger “unsaved changes” dialog for custom post meta changes

The code indeed only looks at the TinyMCE editor or the title and content field if the editor is hidden: window.onbeforeunload = function(){ var mce = typeof(tinyMCE) != ‘undefined’ ? tinyMCE.activeEditor : false, title, content; if ( mce && !mce.isHidden() ) { if ( mce.isDirty() ) return autosaveL10n.saveAlert; } else { title = $(‘#post #title’).val(), … Read more

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

Metabox Data not being saved [closed]

If that is all of your code, you’re missing a save_post action to save the data. Refer to the code sample provided on add_meta_box. add_action( ‘save_post’, ‘save_my_meta_box_data’ ); function save_my_meta_box_data( $post_id ){ // make sure it’s not an autosave if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; // verify your nonce if ( !wp_verify_nonce( … Read more

Categories post-meta Tags metabox, post-meta

metabox upload file

Again. If you are using file upload, it is different than image upload. To get a FILE url, use: $(html).attr(‘href’); File upload: window.send_to_editor = function(html){ var file_url = $(html).attr(‘href’); // Do something with those variables tb_remove(); }; Image upload: window.send_to_editor = function(html){ var file_url = $(‘img’, html).attr(‘src’), classes = $(‘img’, html).attr(‘class’), id = classes.replace(/(.*?)wp-image-/, ”); … Read more

Categories metabox Tags metabox, post-meta

Get aggregate list of all custom fields for entire blog

The function below will store a distinct list of all custom fields for the list of posts/pages/custom posts that is passed to it in the keys of the array $customfields. The array values are the number of posts with the corresponding field. In the example, custom fields added by plugins are excluded ($value[0] != ‘_’;) … Read more

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

Use ajax to update_post_meta

That will not work because you are referring to a single php file, instead the the whole WordPress environment. There’s a easier way to use ajax in WordPress. Use admin_url(‘admin-ajax’) as the form action, then put the function that will answer the ajax call in the theme’s functions.php. More detail here in this answer

Categories PHP Tags ajax, custom-field, mysql, php, post-meta

Inserting Hundreds of Thousands of Posts at Once

There are two reasons I can think of that may cause negative impact wp_insert_post retrieves the post from the DB after writing it to it. this is not fun but should have only a constant impact, so I’m guessing it is not your main problem Each post is being stored in memory as part of … Read more

Categories MySQL Tags mysql, post-meta, wp-insert-post

Formatting custom meta box date from YYYY/MM/DD to a more readable alternative

but when I visit a month with no posts my template returns the date “January 1970” instead. Yes. That will happen. UNIXTIME began on Jan 1, 1970. That is “0000/00/00” but negative numbers work back until sometime in 1901. strtotime will return false for anything outside that range, including your nonexistent dates. date will assume … Read more

Categories custom-post-types Tags custom-field, custom-post-types, date-time, metabox, post-meta
Older posts
Newer posts
← Previous Page1 … Page167 Page168 Page169 … 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