Support » Developing with WordPress » shortcode return 0

  • Resolved Nimesh

    (@nimeshrathod1gmailcom)


    Hello Dev,

    I have create one shortocode :

    [property_list holiday_type_id=48]

    I am call this shortcode using below function :

    
    function resultPropertyList( $atts )
    {
       $final_res = 'my content';
       $final_res = '<script>'
             //AJA CALL WITH SAME FUNCTION 
              resultPropertyList(pagenum);
       $final_res = '</script>'
       return $final_res;
    }
    
    add_shortcode('property_list', 'myPropertyLists');
    function myPropertyLists( $atts )
    {
        return resultPropertyList($atts);
    }
    

    So at the time of click on pagination it can not change my content and return only “0”

    Any idea, where can I make mistake !

    • This topic was modified 2 months ago by  Nimesh.
Viewing 6 replies - 1 through 6 (of 6 total)
  • adnan.limdi

    (@adnanlimdi)

    @nimeshrathod1gmailcom

    can you try this type may be its work

    add_shortcode(‘property_list’, ‘myPropertyLists’);
    function myPropertyLists( $atts )
    {
    return resultPropertyList($atts);

    wp_die();
    }

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    You can’t return an array from a shortcode function. It must return a string.

    Nimesh

    (@nimeshrathod1gmailcom)

    Yes what I’return return $final_res; is a string

    Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    try

    return print_r($final_res, true); to test that.

    Michael

    (@alchymyth)

    review https://codex.wordpress.org/Shortcode_API
    particular https://codex.wordpress.org/Shortcode_API#Handling_Attributes

    and make at least sure to concatente your string bits, like:

    function resultPropertyList( $atts )
    {
       $final_res = 'my content';
       $final_res .= '<script>'
             //AJA CALL WITH SAME FUNCTION 
              resultPropertyList(pagenum);
       $final_res .= '</script>'
       return $final_res;
    };
    Nimesh

    (@nimeshrathod1gmailcom)

    I have solve the issue :

    function resultPropertyList( $atts )
    {
       $final_res = 'my content';
       
       <script>
             //AJA CALL WITH SAME FUNCTION 
              resultPropertyList(pagenum);
       </script>
       if($_POST['action']=='resultPropertyList'){
    	$final_res .= die();
       }
    }
    
    add_shortcode('property_list', 'myPropertyLists');
    function myPropertyLists( $atts )
    {
        //call above function here using the jquery
        $final_res = 'action: "resultPropertyList"
        return $final_res;
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.