I am trying to:
I have created two custom fields that select response (riposte) essays for all essay post types: " riPOSTe to" and " riPOSTe from"
These are both "Select" custom fields with a drop-down menu of all the essay titles. The custom field is working properly, but when I try to display this field (which should show as a title/link to the essay) I can't make it visible. Disregard the older display near the essay title (this is a post reference and will be deleted). I am creating Views for these custom fields and have placed them in the Primary (right) Sidebar as the last two widgets for that sidebar. Here is what I used in the Views to access the custom fields:
<wpv-loop>
[wpv-conditional if="( NOT(empty($(wpcf-riposte-to)))"]
[wpv-post-body view_template="Loop item in riPOSTe to"]
[/wpv-conditional]
</wpv-loop>
then in the the template View:
<div class="riposte-sidebar"><b>This essay is a riPOSTe to:</b> [types field='riposte-to'][/types]
</div>
Link to a page where the issue can be seen: hidden link
I expected to see:
The View lower down on the right sidebar - a link to the related essay.
Instead, I got:
No display, because no value detected?
Well - its confusing, could you please tell me what is your expected output - which link exactly you want to display as [wpv-conditional] shortcode is working - do you mean the expected link is wrongly displayed - If yes - which link you are aiming to display there?
I have applied a strikethrough to the riposte field at the top near the title. That is the Post Reference display that you have recommended I delete, and I will once I get the Views working. On this page, if you scroll down a bit, you will see "This essay is a riPOSTe to:" on the right sidebar. I have removed the conditional to make this text visible. This is a View that is supposed to display the "riPOSTe to" custom field of the essay - this you can find in the dashboard of the essay on the right column under Essay fields. I have set an essay in the dropdown menu for this essay and expect to see the essay displayed in the View. And it is not showing.
Well - I've added following code to your current theme's functions.php file:
This code is used to filter your view based on current post you are displaying. As you are displaying the view using widget there is no way to pass for which post ID you want to filer the view that is why following code needed.
add_filter( 'wpv_filter_query', 'func_display_current_essay_post', 10, 3 );
function func_display_current_essay_post( $query_args, $view_settings, $view_id ) {
global $post;
if ($view_id == 5197) {
$query_args['post__in'] = array($post->ID);
}
return $query_args;
}
Then - I've changed your view's output as given under:
Above code will display the post title link based on the field value riposte-to.
You can even use [types field='riposte-to'][/types] shortcode to display the value but for now there is known issue that is why as a workaround we use [wpv-post-field name="wpcf-riposte-to"] shortcode to get the saved field value with field riposte-to.
Could you please confirm it works for you as well.
Yes, this did work. Thank you. Even though my conditional shortcode is working on most essays - NOT displaying the sidebar "This is a riposte to..." when there is no value set in the dropdown menu - there are occasions when the display shows a link to the same essay of the displayed post, when there is no setting in the custom field. Here for example: hidden link
You will see the sidebar has a link to the same post displayed and in the dashboard nothing is set for the dropdown menus.
I am not sure if this should be a separate ticket, but I extended this method you provided for two other similar Views (extracting from two similar dropdown custom fields) called "riPOSTe from" and "riPOSTe from other". To be clear, each essay may be a response to (riposte to) another essay (this you created for me) or each essay may have one or two responses to it (these I am trying to create). I duplicated the php in the functions.php to get these Views to display - and changed the View ids and the function names.
For example, this page: hidden link
It has two ripostes (response essays) about it. The dropdown custom fields "riPOSTe from" and "another-riPOSTe -from" have the two essays set, the View widgets are set to display in the sidebar. The result is that it gets the "riPOSTe to" displaying to itself (when it shouldn't show at all) and then only the one "riPOSTe from" and not the "riPOSTE from other".
I'm sorry this is so complicated, and I appreciate the help!
Even though my conditional shortcode is working on most essays - NOT displaying the sidebar "This is a riposte to..." when there is no value set in the dropdown menu - there are occasions when the display shows a link to the same essay of the displayed post, when there is no setting in the custom field. Here for example: hidden link
You will see the sidebar has a link to the same post displayed and in the dashboard nothing is set for the dropdown menus.
========>
Well - Yes, I've fixed that issue by adding the conditional statement as given under:
This is because select field will save by default 0 as value if you do not select any option. So we need to check that the field value should be non-zero.
<wpv-loop>
[wpv-conditional if="( '[wpv-post-field name='wpcf-riposte-to']' ne '0' )"]
[wpv-post-body view_template="Loop item in riPOSTe to"]
[/wpv-conditional]
</wpv-loop>
Now, you will not see any link if riposte-to field is not set. Could you please confirm it works at your end as well.
=> hidden link
Yes, could you please open a new ticket, even you can assign it to me - I will be happy to help.