admin管理员组文章数量:1410712
I am displaying a gallery of custom post types. When the user clicks a post, instead of redirecting to a single template, I want it to redirect to another page (too easy just change the link since all redirects go to the next gallery), but I want to be able to use the metadata related to the clicked post on a screen later in the process. In example:
I have three pages. Page one is a gallery of photos using wp_query to display all of my "Photos". Page two is a gallery of "Substrates". Page three is a page that will show the meta data about the photo such as Title and Location and beneath it the substrate data such as Material and Color.
When a user clicks a photo on page one they will be redirected to page two to select a substrate. When a user clicks the substrate they will be taken to page three to show them all the meta about their choices.
How do I collect this info to be used on page three? In my working, non-WP example I added an onclick function to every item displayed. When click is detected, I add variables to localStorage and save the values. Then redirect to next gallery. On page three I'd simply call all the variables from localStorage using JS. I think I can implement this in the WP site but should I be saving the post ID and then when I am ready to display the info about the selections I make a db call? What is the best way to achieve this type of result?
I am displaying a gallery of custom post types. When the user clicks a post, instead of redirecting to a single template, I want it to redirect to another page (too easy just change the link since all redirects go to the next gallery), but I want to be able to use the metadata related to the clicked post on a screen later in the process. In example:
I have three pages. Page one is a gallery of photos using wp_query to display all of my "Photos". Page two is a gallery of "Substrates". Page three is a page that will show the meta data about the photo such as Title and Location and beneath it the substrate data such as Material and Color.
When a user clicks a photo on page one they will be redirected to page two to select a substrate. When a user clicks the substrate they will be taken to page three to show them all the meta about their choices.
How do I collect this info to be used on page three? In my working, non-WP example I added an onclick function to every item displayed. When click is detected, I add variables to localStorage and save the values. Then redirect to next gallery. On page three I'd simply call all the variables from localStorage using JS. I think I can implement this in the WP site but should I be saving the post ID and then when I am ready to display the info about the selections I make a db call? What is the best way to achieve this type of result?
Share Improve this question asked Jan 15, 2020 at 20:04 DavidGDavidG 1133 bronze badges1 Answer
Reset to default 1One option could be to use data attributes on the entires listed on pages one and two. Then attach a click event that reads the attribute value on click saves it to localStorage. This way you wouldn't need to make an extra db call on page three.
In the loop the data attribute value can come basically from anywhere. E.g. post meta, some post field, taxonomy or taxonomy term.
<?php while (have_posts()) : the_post(); ?>
<article class="entry" data-my-attribute="save-me-to-localstorage-onclick">
<!-- gallery image -->
<a><!-- link to next page/view --></a>
</article>
<?php endwhile; ?>
本文标签: pluginsAccessing post39s meta data based on user39s click of a post
版权声明:本文标题:plugins - Accessing post's meta data based on user's click of a post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744827551a2627153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论