Skip Navigation

[Resolved] the functions adding short code don't work anymore

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by charlie 6 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#905155

I am trying to:
to add a shortcode with this function

add_shortcode( 'child-comune', 'child_comune_func' );
function child_comune_func( $atts ) {
$child_posts = types_child_posts('comune');
$res = 0;
if ($child_posts) $res = 1;
return $res;
}

So I can ceck if there are any child types post. In case of yes I will display the child link

with this

[wpv-conditional if="( '[child-comune]' eq 1 )"]


  • Comuni
  • [/wpv-conditional]

    Link to a page where the issue can be seen:
    hidden link
    I expected to see:
    the menu with the only linking button to child page
    Instead, I got:
    all the items as it seems the above mentioned function doesn't work anymore

    #905659

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Charlie,

    Thank you for contacting our support forum.

    You will need to update your code with our New api method here.
    https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post_types
    Thanks,
    Shane

    #907584

    I have understood but i don't have any idea I tried in this way but it won't function

    function toolset_get_related_post( $land_germania, 'child' ){

    if ($land_germania) {
    return != 0;
    }
    add_shortcode( 'child-landgermania', 'toolset_get_related_post(' );
    }

    #907602

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Charlie,

    IN your case you should be able to do this.

    $child_posts = toolset_get_related_post_types( 'child', 'comune' );
    
    

    Please try this and let me know.

    Thanks,
    Shane

    #907677

    Ok that's all right. But I just want to know what kind of output is if an array or a true false.

    In your site you put this as example

    $relationship = toolset_get_relationship('tracks-of-an-album');

    I just want to know if $relationshp is true or an array than add shortcode
    if $relationshp null do nothing

    In my case

    add_shortcode( 'child-comune', 'child_comune_func' );
    function child_comune_func( $atts ) {
        $child_posts = toolset_get_related_post_types('child', 'comune');
      
    }

    How can i say if it is not empyty $chil_posts?

    #908399

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Charlie,

    The return for this function is an associative array.

    https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post_types

    You can actually do this .

    empty($child_posts)

    It will return true if its empty and false if not.

    But you can negate it by doing this.

    if( !empty($child_posts))
    

    So what this is saying if $child_post is NOT empty then do .

    Please let me know if this helps.

    Thanks,
    Shane

    #909240

    The problem is in the new API tool toolset_get_related_post_types which I think is not the right function
    In this page http;//www.araldicacivica.it/stemmi/stato/germania and http;//www.araldicacivica.it/stemmi/stato/italia
    there is the word empty as an example because i used this function

    add_shortcode( 'child-landgermania', 'child_landgermania_func' );
    function child_landgermania_func( $atts ) {
        $child_posts = toolset_get_related_post_types('child', 'land-germania');
     if (!empty($child_posts))
    	
    	
    	 
      { echo 'empty'; }
    }

    So the problem is in the function. Not after.
    What I want is that in the page italy I do not want show the menu Lander Germania (because there is not the child types lander)
    Instead in the second page I want the menu which indicates me that germany has landers as child types.
    The related posty typed is general but I want in this specific case. n early version was so simple. Now I don't know which function is the best to achieve this.

    thank you

    #910663

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Charlie,

    I took a look at this for you again.

    SO the correct function should be.

        $child_posts = toolset_get_related_posts( get_the_ID() , 'stato_comune', 'parent' );
    
    

    This should give you the child posts.

    Thanks,
    Shane

    #910723

    thank you very much that's work perfectly. So sorry to take so much time for you. You are the best! Carletto