Skip Navigation

[Resolved] Trying to display parent post link, but child link is shown

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

Problem:
The Child Field is shown instead of the Parent Field, in a View querying Child Posts.

Solution:
The issue is always the same in this case.

1. The Parent Post information you want to display is not existent or not connected to the Child Post queried in the View
2. The Parent info is not called correctly

After reviewing the above mandatory settings, you can avoid to fallback to the Currently Queried Post's field by evaluating first if the Parent Field exists.
If not, display nothing.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ > Checking If A Parent Exists

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by gavinS 8 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#367181
1st Interviews problem.png

I am trying to display a list of parent post links, but for some reason the child link is being displayed?

I have a type called 'status-change', with a parent called 'cv-sent'.

I have created a view of status changes and my loop output is as follows:

<h3>1st Interviews in last 7 days by [wpv-post-param var="author-filter"]</h3><br>
[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          [wpv-post-link id="$cv-sent"] &nbsp&nbsp
          [types field="cv-status" id="$cv-sent"][/types]<br>
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

I'm expecting to see a list of the parent (cv-sent) links and their statuses, but instead I'm seeing a list of the child (status-change) links.

#367242

Always when you call a Parent Post information, and the currently Queried Post Tipe info is returned, it means that the Parent information is either missing or not called correctly.

It's sort of a "fallback" of Views.
If Views can't get the parent info, it will return the Current Post info.

So the possible issues here are:
1. The Parent Post information you want to display is not existent or not connected to the Child Post queried in the View
2. The Parent info is not called correctly

Looking at your Code, this is the suggested fix:
(read inline comments for further details)

//I don't know what wpv-post-param is, but it's not a Toolset ShortCode
//Please don't use wpv-prefixes for Custom ShortCodes, as it might conflict in case we do create similar ShortCodes in future.
<h3>1st Interviews in last 7 days by [wpv-post-param var="author-filter"]</h3><br>
[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
        <wpv-loop>
//Below I added a conditional HTML check to first see if the parent exists.
//I assume the Slug of your Post parent is cv-sent

[wpv-conditional if="(NOT(empty($(_wpcf_belongs_cv-sent_id))))"]

//below is your current call for the parent post info
[wpv-post-link id="$cv-sent"] &nbsp&nbsp
 [types field="cv-status" id="$cv-sent"][/types]<br>

//End of conditional
[/wpv-conditional]
         
        </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]

You must ensure that the Parent exists for the current Child Post, to display it's data.

More infos about this here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ > Checking If A Parent Exists

Please let me know if the above solution works for you, I look forward to your reply!

Thank you for your patience.

#367471
Post relationship.png

Hi Beda

Hmm... That's interesting. I'm not sure where I found wpv-post-param, but it's not a custom shortcode that I've created, and it is not registered as a custom shortcode in view settings. And yet it works. I wanted a way to display the URL parameter author-filter in the output, and it does that. Is there another way to display that author?

The parent does exist and is connected. I have attached a screenshot of the connection for that post (CV Status - 1455615885) So I would expect this view to output the name of the parent (This is a test).

In fact these posts are automatically created to store changes to a radio field in the CV-Sent type, so they should always have a connected parent. (I think I created this function with help from you actually). It shouldn't be possible for there to be no parent. Here is the code which creates these status-change posts:

function record_status_change($form_data)
{
    // if Edit CV status form
    if ($form_data['id']==209) //CRED Form ID
    {
  
        //get existing post id
        $existing_post_id = $form_data['container_id']; //Current CONTAINER of Form (current Post)
        //https://toolset.com/documentation/user-guides/cred-api/#cbsd
 
        //get existing post field value
        $existing_post_status = get_post_meta($existing_post_id, 'wpcf-cv-status', true); //Get post meta value of currnet post
  
        //get new field value
        $new_field_value = $_POST['wpcf-cv-status']; //get value of current CRED Form field
  
            //If value has changed
            if ($existing_post_status != $new_field_value) //if this is not the same
            {
  
            //if, then insert the new post
            //values please refer to this DOC:
            //https://codex.wordpress.org/Function_Reference/wp_insert_post
             $my_post = array(
              'post_title'    => ('CV-status - '.date('U')),
              'post_content'  => ('Status change to '.$new_field_value),
              'post_status'   => 'publish',
              'post_type' => 'status-change'
                            //follow the DOC to add more or less arguments
            );
 
            //insert post and VERY imporntat assing the $varaible of the Post ID for later Usage!
            $new_post_id = wp_insert_post( $my_post, $wp_error );
  
            $current_date = date('U'); //AS example for timestamp date('U')
            //See: <em><u>hidden link</u></em>
            
 
            //NOW Update the new posts fields! required.
            //(it shoudl automatically create them if non-existent)
           
            update_post_meta($new_post_id, 'wpcf-datestamp', $current_date);
            update_post_meta($new_post_id, 'wpcf-value', $new_field_value);
            update_post_meta($new_post_id, '_wpcf_belongs_cv-status_id', $existing_post_id);
  
        }
    }
}
add_action('cred_before_save_data', 'record_status_change',10,1);
#367473
Fixed.png

Oh snap. This has started working all on its own.. Weird..

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