Skip Navigation

[Resolved] How to display current page fields on view

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

Problem:
How to display current page fields on view

Solution:
You can use the types shortcode argument item='$current_page' to display the custom field value belongs to current page.

For example:

[types field='test-single-line' item='$current_page'][/types]

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/split-use-a-view-to-display-data-from-the-current-page-only-custom-field-display-issue/#post-1165328

Relevant Documentation:
https://toolset.com/documentation/user-guides/displaying-brother-pages/#5

This support ticket is created 5 years, 11 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 10 replies, has 2 voices.

Last updated by Ben 5 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1162726

Ben

Thank you for your reply Luo Yang. That works very well!

Just a question out of interest regarding my original post.
Do you know why that, in a View when there are no results from the query and therefore nothing displayed inside <wpv-loop></wpv-loop>, this also seems to affect the Custom Fields inserted within the view but outside of <wpv-loop> tags. These Custom Fields will not show in this situation.

#1162728

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

well - could you please share your view's loop output content and what you are trying to display, I mean which fields?

#1163066

Ben

Hello Minesh.

I think I have managed to figure part this one out myself. Although the Custom Fields were inserted outside of the <wpv-loop> tags, they were still within the [wpv-items-found], so when no results were found for the query, the Custom Fields were not being displayed either.

I can make this work now by duplicating the Custom Fields and inserting them within both the [wpv-items-found] and the [wpv-no-items-found] tags.

Can I do this any other way without having to duplicate them and only having the Custom Fields inserted once in the View? I tried the below and this doesn't seem to be working. It always outputs the [/wpv-no-items-found] tag, regardless of whether there are items found, as well as the required data.

[wpv-layout-start]
	***QUERY RESULTS HERE***
	<!-- wpv-loop-start -->
	<ul class="wpv-loop js-wpv-loop">
		<wpv-loop>
			[wpv-post-title]
		</wpv-loop>
    </ul>
<br><hr><br>
[wpv-no-items-found]
***CUSTOM FIELDS HERE***
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[/wpv-no-items-found]
[wpv-layout-end]

Have I written this wrong? Or is there another way of doing it?

#1163601

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I need to know what custom field you added. The thing is that when there is no items found - the custom field you try to display for which post ID? so, when no results found, from which Post ID you want to display the custom field values?

#1163654

Ben

The Custom Fields are various different Custom Fields, all using =item'$current_page'. For example:

[types field='test-single-line' item='$current_page'][/types]
#1163702

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - as you are trying current page - it should display the current page value for a field 'test-single-line'.

If this is not working, I need to check first on your install and for that I need problem URL where you added the view and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1163739

Ben

Minesh, I think you are misunderstanding the problem I am having now.

Those Custom Fields output fine using the code provided in reply #1163066, the only issue is that I seem to have to duplicate the Custom Fields code within both the [wpv-items-found] and the [wpv-no-items-found] tags for it to show in both instances. When I try to use the above code, (from reply #1163066) where I have "overlapped" the [wpv-items-found] and the [wpv-no-items-found] tags, I also get the physical output of "[/wpv-no-items-found"] in addition to what I want to show.

I can make it work by duplicating the Custom Fields I require to be shown both within the [wpv-items-found] and the [wpv-no-items-found] tags. I was just wondering if there was an easier way where I do not have to duplicate the code? This would mean I only have to update one area rather than two.

I hope that makes more sense now? Anything else you need, please let me know.

#1164785

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I really need access to see whats happening because if I can see things live I can understand better rather than having reading hundreds of words. That will guide me to guide you in the right direction as well. Few screenshots?

or

What if you try to add the said shortcodes just after the [wpv-layout-start] shortcode?

#1165037

Ben

Let me try simplify and explain again. If you need more of an explanation or need to see it live after this then I can grant you access to a staging version if you would prefer that.

This is what I am using in the Loop Editor:


[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
Custom Field:[types field='test-single-line' item='$current_page'][/types]
    <wpv-loop>
      [wpv-post-title]
    </wpv-loop> 
    <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-no-items-found]
Custom Field:[types field='test-single-line' item='$current_page'][/types]
[/wpv-no-items-found]
[wpv-layout-end]

This is working fine for what I am trying to achieve.

But, If you notice that the Custom Field has to be inserted once within the [wpv-items-found] and once within the [wpv-no-items-found] tags to ensure that they display regardless of whether the query returns any results.

I am trying to find out if there is any way I can achieve the same results without having to duplicate the line of:

Custom Field:[types field='test-single-line' item='$current_page'][/types]

I have tried overlapping the [wpv-items-found] and [wpv-no-items-found] tags, but this always causes one of the shortcut tags to output and doesn't work as required.

I hope I have explained that well enough?

#1165328

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - what if you try to use following:

[wpv-layout-start]
Custom Field:[types field='test-single-line' item='$current_page'][/types]
    [wpv-items-found]
    <!-- wpv-loop-start -->
    <wpv-loop>
      [wpv-post-title]
    </wpv-loop> 
    <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-no-items-found]
[/wpv-no-items-found]
[wpv-layout-end]

OR

Custom Field:[types field='test-single-line' item='$current_page'][/types]
[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
    <wpv-loop>
      [wpv-post-title]
    </wpv-loop> 
    <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-no-items-found]
[/wpv-no-items-found]
[wpv-layout-end]

OR

[php]
[wpv-layout-start]
    [wpv-items-found]
    <!-- wpv-loop-start -->
    <wpv-loop>
      [wpv-post-title]
    </wpv-loop> 
    <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-no-items-found]
[/wpv-no-items-found]
[wpv-layout-end]
Custom Field:[types field='test-single-line' item='$current_page'][/types]

Does any of the aboe method works?

#1165519

Ben

Thank you Minesh.

All three of those solutions work.