• Hi,

    First of all thank you for fabulous Contact Form 7 – Dynamic Text Extension plugin.

    I have a peculiar need though.. I’ve crated a contact page for each service on a webiste I’m building.. so each service (there are 7) are the parent page for each contact page. Because of that and the website has support for 9 languages, what I’ve done is add the recipient email for every service page and then get that field within the contact page like this:

    get_field('recipient_email', $post->post_parent);

    I checked your code and in my case instead of retrieving the $post_id I need the $post->post_parent:

    So from this
    if(isset($post)) $post_id = $post->ID; Original line

    To this:
    if(isset($post)) $post_id = $post->post_parent;

    I would rather not modify the original code, so I can get future updates. Maybe you could add a filter hook and then apply_filter(), so I could apply my change without changing your code 🙂

    Thanks!
    Lluc

    This is the original code:
    /* Insert a Custom Post Field
     * New in 1.0.4
     */
    function cf7_get_custom_field($atts){
            extract(shortcode_atts(array(
                    'key' => '',
                    'post_id' => -1,
                    'obfuscate'     => 'off'
            ), $atts));
    
            if($post_id < 0){
                    global $post;
                    //if(isset($post)) $post_id = $post->ID; Original line
                    if(isset($post)) $post_id = $post->post_parent; // My line
            }
    
            if($post_id < 0 || empty($key)) return '';
    
            $val = get_post_meta($post_id, $key, true);
    
            if($obfuscate == 'on'){
                    $val = cf7dtx_obfuscate($val);
            }
    
            return $val;
    
    }
    add_shortcode('CF7_get_custom_field', 'cf7_get_custom_field');
  • The topic ‘Add filter hook’ is closed to new replies.