Views code not accessing custom field
- This topic has 7 replies, 2 voices, and was last updated 9 months ago by
Josh Weitzman.
-
AuthorPosts
-
July 19, 2024 at 8:07 PM #45948
Josh Weitzman
ParticipantHello -
I'm having a problem with custom fields and views code. I have a website with posts of news items. There is a page on the website with a posts list consisting of the title and an exerpt and a button that I would like to send the viewer to an external webpage to read more about the post.
For that button I'm using a custom field on the post page - the field is jw_url. Ive written code in Views to make a button that has as it's href the custom field (jw_url) from each post. I can not get it to work.
First - the short code keeps dissapearing from my page code. How do I make the short code persist? And how do I get the basic functionality of the link to work? Once I do that I can make the button created in Views look better.
Here are some screenshots and code:
Here is the code of the webpage with the news post feed:
Here are some screenshots:
Custom Fields page:
https://photos.fife.usercontent.google.com/pw/AP1GczPxXXc5XeMh6Ya_qG4vvf2_OWURaLgzS_72u1t7R6x2Ayiw1fn7MpsQlA=w1274-h646-s-no-gm?authuser=0Post with custom field entered:
https://photos.fife.usercontent.google.com/pw/AP1GczNFQFecfTT2wXrzdtva2LwnZ9YdWHC3KVFmEAjp-iFeVtC_sWJF1bfaoQ=w1274-h635-s-no-gm?authuser=0If there's any help you could offer - I would appreciate it. I can't get the short code to stay and I cant get the code to access the blog post custom field.
Thanks for your help.
Josh
July 21, 2024 at 3:46 PM #45959Peter
ModeratorHello Josh,
Screenshots are broken, can you please share them again? Also, please share some screenshots of the view template, code content and settings.
July 21, 2024 at 7:00 PM #45965Josh Weitzman
ParticipantHello -
Here are the screenshots again -
Custom Fields:
https://postimg.cc/2bvP8k0ZViews Code:
https://postimg.cc/BP59NSD0Custom Field Settings:
https://postimg.cc/w3k9h2ksPost with Custom Field entered:
https://postimg.cc/mtXRnrJLHope this is what you need and thanks for your help.
Josh
July 22, 2024 at 10:41 PM #45973Peter
ModeratorHello,
You are inserting the view shortcode in the loop so the
post
in the view code might be the current post object, not the post in the loop.
You can try to use this code in the view template:{% set current_post_id = mb.get_the_ID() %} {{ mb.rwmb_meta( 'jw_url', '', current_post_id ) }}
Let me know how it goes.
July 25, 2024 at 1:45 AM #46000Josh Weitzman
ParticipantHello Peter -
Thanks for your response. I've had a chance to try the code.
I've tried this version:
https://postimg.cc/Js4sLP9cand also this version:
https://postimg.cc/qzQ7j2ztNeither optioin resulted in any change on my webpage.
Any other ideas?
Also- my shortcode keep disapearing from the page code. I need to retype it in every time I view the page.
Thanks again,
Josh
July 25, 2024 at 9:59 PM #46009Peter
ModeratorHello,
Please share your site admin account and details of the issue by submitting this contact form https://metabox.io/contact/
I will take a look.July 26, 2024 at 8:28 PM #46017Peter
ModeratorHello,
Currently, it isn't possible to get the post ID of the post in the Query Loop block of WordPress. It is a bug of WordPress itself, you can get more information in this topic https://wordpress.org/support/topic/query-loop-block-get-display-each-post-id/
Or you can create a loop with View template and add the shortcode to the page content. Please follow this topic https://support.metabox.io/topic/reusable-template-parts/
July 27, 2024 at 8:16 AM #46027Josh Weitzman
ParticipantHello Peter -
Thanks for your help with this. As you suggested I created a post archive template in Views and it is accessing the custom fields, no problem.
So this plan works. The issue is settled as far as I'm concerned.
Thanks again,
Josh
-
AuthorPosts
- You must be logged in to reply to this topic.