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

WooCommerce conditional meta query

The default relation for a meta query is AND, so when you have two conditions they will be treated as such: $meta_query[] = array( ‘key’ => ‘_stock’, ‘value’ => ‘0.000000’, ‘compare’ => ‘NOT IN’ ); $meta_query[] = array( ‘key’ => ‘_backorders’, ‘value’ => ‘no’, ‘compare’ => ‘!=’ ); Get all products with a _stock meta … Read more

Categories woocommerce-offtopic Tags meta-query, post-meta, woocommerce-offtopic

How to display multiple Post meta_key/meta_values by SQL query

change where clause with or SELECT P.ID, P.post_title, P.post_content, P.post_author, meta_value FROM wp_posts AS P LEFT JOIN wp_postmeta AS PM on PM.post_id = P.ID WHERE P.post_type=”post” and P.post_status=”publish” and ( meta_key = ‘job_title’ or meta_key = ‘company_email’ ) ORDER BY P.post_date DESC but this sql will return the same post in 2 row for your … Read more

Categories PHP Tags custom-field, php, post-meta, sql

Meta query interfering with orderby relevance

So after @Nicolai found that blurb in the WP source confirming that I can’t use multiple parameters in the orderby if I am ordering by relevance I had to go a different route. However, this route only works if I don’t care for pagination. There probably is a way to put it back, but I’m … Read more

Categories Database Tags database, meta-query, order, post-meta, pre-get-posts

Meta keywords and descriptions plugin for manually editing meta for each page/post

the simple solution would be to paste this snippet of code in your theme’s functions.php file : add_action(‘wp_head’,’keywords_and_desc’); function keywords_and_desc(){ global $post; if (is_single()||is_page()){ if(get_post_meta($post->ID,’my_keywords’,true) != ”) echo ‘<meta content=”‘.get_post_meta($post->ID,’my_keywords’,true).'” name=”keywords”>’; if(get_post_meta($post->ID,’my_description’,true) != ”) echo ‘<meta content=”‘.get_post_meta($post->ID,’my_description’,true).'” name=”description”>’; } } And the just add keywords and description using the built in custom fields on a … Read more

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

How to set author for post AND post attachments

Use this in your theme’s functions.php: add_filter( ‘add_attachment’, ‘wpse_55801_attachment_author’ ); function wpse_55801_attachment_author( $attachment_ID ) { $attach = get_post( $attachment_ID ); $parent = get_post( $attach->post_parent ); $the_post = array(); $the_post[‘ID’] = $attachment_ID; $the_post[‘post_author’] = $parent->post_author; wp_update_post( $the_post ); }

Categories attachments Tags attachments, author, post-meta

Change slug with custom field

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’); function set_slug($post_id){ $new_slug … Read more

Categories posts Tags permalinks, php, post-meta, posts, slug

Adding an assisting editor box to Post page

add_meta_box should give you the box container like your have pictured. You have a select drop-down because that is what you created here: echo ‘<select name=”rating”>’; echo ‘<option value=””‘ . ((($value == ”) || !isset($ratings[$value])) ? ‘ selected=”selected”‘ : ”) . ‘> Untouched </option>’; // output each rating as an option foreach ($ratings as $id … Read more

Categories post-meta Tags metabox, post-meta

Add a meta description to home page?

You do not need to add Yoast if you only want to add meta tags to the homepage. Just some minor editing will save you on performance. You can use the is_home() function. Insert this to your header.php: <?php if (is_home()) { ?> <meta name=”description” content=”Your description for homepage…” /> <?php } else { ?> … Read more

Categories metabox Tags homepage, metabox, plugin-wp-seo-yoast, post-meta

wp_insert_post() getting slower the more posts

I found the solution by the comment from birgire what tells to use wp_defer_term_counting() as follows: if( ! $errors ) { // Set wp_defer_comment_counting(); wp_defer_term_counting( true ); foreach( $lines as $line ) { // Import post $args = array( ‘post_title’ => $new_vipost_title, ‘post_content’ => $new_vipost_content, ‘post_status’ => ‘publish’, ‘post_type’ => $vipost_type, ); $post_id = wp_insert_post( … Read more

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

Update Multiple Post Meta for the Same Post In One call?

EDIT: Original answer was inaccurate as you can do this with wp_update_post and the meta_input field As per the updated question and comments this is possible with wp_update_post (or wp_insert_post for a new record) using the meta_input key on the array, e.g.: $metaValues = array( ‘key1’ => ‘value1’, ‘key2’ => ‘value2’, // … as many … Read more

Categories plugins Tags php, plugin-development, plugins, post-meta, theme-development
Older posts
Newer posts
← Previous Page1 … Page186 Page187 Page188 … 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