Delete posts based on post meta data
DELETE wp_posts FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_id = wp_posts.ID WHERE (wp_postmeta.meta_key = ‘InternalOnly’ AND wp_postmeta.meta_value IS NOT NULL);
DELETE wp_posts FROM wp_posts INNER JOIN wp_postmeta ON wp_postmeta.post_id = wp_posts.ID WHERE (wp_postmeta.meta_key = ‘InternalOnly’ AND wp_postmeta.meta_value IS NOT NULL);
The issue is that you are using get_post_meta(), but since you’re hooking wp_insert_post_data you have not set the post meta yet (because the hook fires before the post is inserted into the database. You should be pulling from the metadata submission, and running through any filters you use for update_post_meta(). If you post the code … Read more
You need a custom walker. Change the function function start_el() to use your custom field’s value.
<?php $args = array( ‘post_type’ => ‘attachment’,***’meta_key’=>’your meta key’,’meta_value’=>’your meta value’,*** ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { echo apply_filters( ‘the_title’ , $attachment->post_title ); the_attachment_link( $attachment->ID , false ); } } ?>
I was looking at this answer earlier. It shows you how to remove fields from the Media Uploader, so maybe it’ll set you on the right lines for writing an additional function to incorporate into the Uploader?
(See codex) update_post_meta() calls update_metadata(‘post’, $post_id, $meta_key, $meta_value, $prev_value); This function is here. And there are plenty of hooks/filters: (In example of ‘post’, $meta_type=”post”) Before metadata is updated: update_{$meta_type}_metadata (here) Filter –If this returns anything other than ‘null’, the metadata won’t save update_{$meta_type}_meta (here) Action After metadata is updated: updated_{$meta_type}_meta (here) Action updated_post_meta (here) Action … Read more
As has been mentioned in the comments – changing the post type of a post only changes its ‘post type’ column. All post metadata is associated with the post ID and this never changes. However, you may not see this information: if the old post type had a metabox or taxonomy associated with that, that … Read more
You have syntax error in query arguments: ‘orderyby’.
There are a few issues that break your code: $post doesn’t exist, you’d need to import it using global, or simply use get_the_ID as you’re already doing $check[”] won’t return anything since it will access an undefined index, outside of the empty construct it would trigger a warning I can’t test it right now, but … Read more
$args = array( ‘meta_key’ => ‘home_post_id’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘home_post_id’, ‘value’ => 0, ‘compare’ => ‘>’, ‘type’ => ‘numeric’, ) ) ); query_posts($args); Something like this should work but I haven’t tested it .) Let me know if it works.. Reference: WP_Query – Custom Field Parameters