Skip Navigation

[Resolved] Problems on Post Parent

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to get the post parent of the same post type using PHP.

Solution:
This can be done by using the function below.
$parent_id = wp_get_post_parent_id( get_the_ID() );

This works when the post parent is the Same Post Type.

This support ticket is created 5 years, 10 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.

Our next available supporter will start replying to tickets in about 0.09 hours from now. Thank you for your understanding.

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 19 replies, has 2 voices.

Last updated by santiagoF 5 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1163777

I am trying to: I have tried different methods but I can not get it.

Link to a page where the issue can be seen:
The URL with correct background color: hidden link
The URL with error to get Parent Background Color: hidden link

I expected to see: I hope to see the background color

Instead, I got: Nothing.

#1163856

Shane
Supporter

Languages: English (English )

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

Hello,

Thank you for contacting our support forum.

Could you let me know where the background color is being retrieved from ?

Also could you let me know the code that is being used for this ?

Thanks,
Shane

#1163895
003.jpg
002.jpg
01.jpg

Hello @Share, im using the try using the following code on my header.php

 <?php $bg_color = do_shortcode( "[types field='color-del-curso' id='$parent'][/types]" );?>
 <div class="content_inner"  <?php echo "style='background-color:". $bg_color ."'";?>>

This code is able to apply the background color to the container as it appears in the url:
hidden link

The problem is that I can not make it apply to the child post, the $parent not work:
hidden link

This code has been tested to verify that if I read the ID of the post father and if he reads, but of course this would not be dynamic:

 <?php $bg_color = do_shortcode( "[types field='color-del-curso' item='400618'][/types]" );?>

Other code base on you documentation:

 <?php $bg_color = do_shortcode( "[types field='color-del-curso' item='@cursos-presenciales.parent'][/types]" );?>

I also tried to follow its documentation and it does not show me, anyway I do not know how to do it so that from PHP, which is where I am applying the fund, I get it from Post Parent.

Thanks.

#1164014

Shane
Supporter

Languages: English (English )

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

Hi Satiago,

How is the relationship between the posts done?

Is it a one-to-many relationship that was setup in Types?

Please let me know.

Thanks,
Shane

#1164018
11.jpg

The relationship is by post.
Since the structure of the course is:

- Landing Page <-- This landing has all the fields that are filled in types.
----- Thanks page <-- This landing of thanks shows everything that I place in the Main Landing.

What does not work is the Parent within PHP

#1164067

Shane
Supporter

Languages: English (English )

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

Hi Santiago,

I see the issue now.

Try this.

$parent_id = wp_get_post_parent_id( get_the_ID() );
<?php $bg_color = do_shortcode( "[types field='color-del-curso' item="'.$parent_id.'"][/types]" );?>

Please Try this and let me know the results.

Thanks,
Shane

#1164734
docente.jpg

Hello @shane,
Thanks, it worked perfect and now the color changes without problems.

We can review the same problem but it is already internally related without PHP coding.

The teachers are loaded from the Main Landing but they are not showing in the child.
I have tried in this way, but it does not work.

Test 01

{!{wpv-view name='docentes-del-curso' item='@docentes-del-curso.parent' orderby='titúlo'  order='asc' cached='off'}!}

Test 02

{!{wpv-view name='@docentes-del-curso.parent'  orderby='titúlo'  order='asc' cached='off'}!}

Thanks

#1164849

Shane
Supporter

Languages: English (English )

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

Hi Santiago,

So just to confirm here, you are trying to retrieve the child posts using this view correct? Are the parents being loaded on this page as well ?

Please let me know.

Thanks,
Shane

#1164881
paa02.png
paa.png
1224124124.jpg
12412412.jpg

It is correct, the information displayed on the page is being obtained from the langing parent.
How could we do?

Check attachment:
Thanks

#1164986

Shane
Supporter

Languages: English (English )

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

Hi Santiago,

Mind if I took a look at where the view is added to the page?

The private fields will be enabled so that you can provide the credentials.

Thanks,
Shane

#1165538

Shane
Supporter

Languages: English (English )

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

Hi Santiago,

I dont think this one is going to be possible.

Because in order to select Karen Goldman to add to this page hidden link

You will need to be displaying something from its parent as well. From what I can see there isn't a reference to the parent on this page.

The other alternative is to manually specify the parent in the view to display the child post.

Thanks,
Shane

#1165625

Hello, the profile Karen Goldman is loaded on "Parent" landing:
hidden link

And the idea is to show on the daughter page which is this:
hidden link

All of the more custom fields are loaded from the parent page and works perfectly but I can not do this with the teacher.

Thanks.-

#1165747

Shane
Supporter

Languages: English (English )

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

Screenshot 2018-12-13 at 2.21.13 PM.png

Hi Santiago,

You just want to load the child correct?

So what you can do is to set the view to get the parent ID by using a shortcode parameter. See Screenshot

Then you can pass the ID of the parent into this view and it should resolve the issue for you.

Thanks,
Shane

#1165784

Can you make the configuration if it works?
Thanks!

#1165807

Shane
Supporter

Languages: English (English )

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

Hi Santiago,

Since the site is in a different language it makes it difficult to navigate.

Can you point me to a point on the page on the backend that refers to the parent?

This will greatly help to make some linkage.

Thanks,
Shane

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.