Support Forum
Hello -
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=0
Post with custom field entered:
https://photos.fife.usercontent.google.com/pw/AP1GczNFQFecfTT2wXrzdtva2LwnZ9YdWHC3KVFmEAjp-iFeVtC_sWJF1bfaoQ=w1274-h635-s-no-gm?authuser=0
If 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
Hello Josh,
Screenshots are broken, can you please share them again? Also, please share some screenshots of the view template, code content and settings.
Hello -
Here are the screenshots again -
Custom Fields:
https://postimg.cc/2bvP8k0Z
Views Code:
https://postimg.cc/BP59NSD0
Custom Field Settings:
https://postimg.cc/w3k9h2ks
Post with Custom Field entered:
https://postimg.cc/mtXRnrJL
Hope this is what you need and thanks for your help.
Josh
Hello,
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.
Hello Peter -
Thanks for your response. I've had a chance to try the code.
I've tried this version:
https://postimg.cc/Js4sLP9c
and also this version:
https://postimg.cc/qzQ7j2zt
Neither 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
Hello,
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.
Hello,
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/
Hello 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