Support » Developing with WordPress » Update_Post_Meta Isn’t Working On Functions.php

  • Hi. I wrote a code and added to my functions.php on my WordPress site. Theme is a coupon theme.

    If offer URL is filled, it shows a “go to offer” button; if not filled, it doesn’t show.

    Also there is a brand of offer; brand has a general homepage URL.

    I want to assign brand URL to offer URL when offer URL is blank.

    I wrote a code, and too see if it’s working, i added shortcode. it shows the brand URL with shortcode correctly but button doesn’t show. I couldn’t find where the problem is? Please help.

    Then i tried with Update_Post_Meta, it didn’t work.
    even for manually added ID, still don’t work.

    update_post_meta( '3110', 'rehub_offer_product_url', $brandurl);

    here is mysql db screenshot:

        add_filter('rh_no_brand_url', 'emreboslinkyonlendir',1000, 2);
        function emreboslinkyonlendir($offurl, $postid=''){
                $postaid = $postid;
                $postaid = get_the_ID(); //get id of opened post
                $offurl = get_post_meta($postaid, 'rehub_offer_product_url', true);
                $termaids =  wp_get_post_terms($postaid, 'dealstore', array("fields" => "ids")); //find brand of the post
                $termaid = $termaids[0];  //find first of array       
                $brandurl = get_term_meta( $termaid, 'brand_url', true ); //get brand_url column
                $offurl = esc_url($brandurl);
                //$offer_url = ( $brandurl );
            return $offurl;
       add_shortcode( 'offurl' , 'emreboslinkyonlendir' ); //for testing, to see i added a shortcode if it's working


Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    All the shortcode does is display an URL, the button would be accomplished through other means. One possibility would be to build a shortcode that outputs the entire form element, fields, URL, button, everything. The shortcode handler can try to get the URL from post meta, and if there is no such record, use a default value (or leave the field blank).

    It’s not clear in what context you’re trying to save the URL with update_post_meta(). Ideally it should be used by whatever code handles the form submittal. That in turn is determined by the form element’s action attribute.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.