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"]   
[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.
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"]   
[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.
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);
Oh snap. This has started working all on its own.. Weird..