Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have setup a custom meta_key for attachments. Since it is a radio button with Yes/No options, and the default value is always Yes, I need that this default value is saved into the db when the attachment is created.

Right now the problem is that when I upload an image, the Edit Media page shows me that the value for this meta_key is "Yes", but it is actually not saved in the database until I click "Save All Changes" or "Update Media".

Since these attachments can be added both by manually uploading files and automatically by importing an RSS feed, I need the default value to be created at the moment the attachment is created in the db.

UPDATE: To explain the issue in more detail, this is the code I am using in the template to find the attachments. I don't know if I can modify this to also query the attachments when the _show_attach is null?

$attached_photos = get_children(array(
        'post_parent'    => get_the_ID(),
        'post_type'      => 'attachment',
        'numberposts'    => -1, // show all
        'post_status'    => null,
        'post_mime_type' => 'image',
        'order' => 'ASC',
        'orderby' => 'menu_order',
        'meta_key' => '_show_attach',
        'meta_value' => 'false',
        'meta_compare' => '!='
    ));
share|improve this question
add comment

1 Answer

Why not cover this in your query and use isNull() ? When your meta_key is null for this attachment it is true.

share|improve this answer
    
I would, but I do not know how - please see the updated question for the code I am using. I don't know if there is a way for me to also query for attachments that _show_attach is null (or to be exact, it is missing altogether) in the same query. –  ragulka Aug 21 '12 at 8:28
    
you can always use wpdb to make complex queries codex.wordpress.org/Class_Reference/wpdb –  woony Aug 21 '12 at 8:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.