Kjapp og trygg hosting for Wordpress

Autmatisk legge til bilde-URL i custom field

Demilio

Medlem
Noen som vet hvordan man kan lage custom field automatisk når man laster opp bilde? Evt om det finnes en plugin for detten?

Med andre ord prøver jeg å legge inn en funksjon som auomatisk legger til et custom-field med URL til det første bildet som ble lastet opp i innlegget.

Noen som kan hjelpe?
 

Demilio

Medlem
Stilig, greia er at jeg er veldig avhengig av at URL skal ligge i custom field pga at jeg bruker wordpress multisite og sitewide tags plugin.

Long story short... så bruker jeg custom field og timthumb for å hente inn bilder globalt

evt.. kan jeg bruke noe av codex'en du sendte til det?
 

Demilio

Medlem
Her er koden her har hittil. Trenger å bytte ut "VALUE" med nettadressen til thumbnail

Kode:
add_action('wp_insert_post', 'mk_set_default_custom_fields');
    function mk_set_default_custom_fields($post_id)
    {
        if ( $_GET['post_type'] != 'post' ) {
            add_post_meta($post_id, 'Image', 'VALUE', true);
        }
        return true;
    }
 

Demilio

Medlem
Her er løsningen for dne som skulle behøve det :)
Kode:
function w_thumbnail_src() {
    if (has_post_thumbnail()) {
        $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'emphasis');
        return $thumb[0]; // thumbnail url
    } else {
        return '';  // or a default thumbnail url
    }
}


add_action('publish_page', 'add_custom_field_automatically', 'w_thumbnail_src');
add_action('publish_post', 'add_custom_field_automatically');
function add_custom_field_automatically($post_id) {
global $wpdb;
if(!wp_is_post_revision($post_id)) {
add_post_meta($post_id, 'Image', w_thumbnail_src(), true);
}
}
 
Topp