Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1435822
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm using WP Job Manager Plugin.
I want to make a link on the [job_dashboard] page which allow users to make featured their jobs.
I'm added this code to job-dashboard.php:
echo '<li><a href="' . update_post_meta( $job->ID, '_featured', 1 ) . '">Featured</a></li>';
But this is make featured all of my jobs not the one where I clicked the link.
How can I do that make featured the one which I clicked?
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionI'm using WP Job Manager Plugin.
I want to make a link on the [job_dashboard] page which allow users to make featured their jobs.
I'm added this code to job-dashboard.php:
echo '<li><a href="' . update_post_meta( $job->ID, '_featured', 1 ) . '">Featured</a></li>';
But this is make featured all of my jobs not the one where I clicked the link.
How can I do that make featured the one which I clicked?
Share Improve this question asked Apr 1, 2019 at 21:24 gezukagezuka 175 bronze badges1 Answer
Reset to default 0Short answer: you're doing it wrong.
Long answer
update_post_meta
actually updates the field, so whenever your code runs, the value of _featured
is updated to 1
. No clicking necessary, you're actually telling it to update the value right then and there.
What you should do is have your link point to a page that can handle the request when the link is clicked:
echo '<li><a href="' . add_query_arg( 'set_featured_id', $job->ID ) . '">Featured</a>';
Then, process that information:
add_action( 'init', function() {
$job_id = filter_input( INPUT_GET, 'set_featured_id', FILTER_VALIDATE_INT );
if ( null === $job_id ) {
return;
}
update_post_meta( $job_id, '_featured', 1 );
});
The above solution is really insecure, however. You should probably look at functions to "gate" whether the user can do this - such as current_user_can
- you could also look into doing this as part of a form submission, which would allow you to leverage wp_nonce_field
as well for some added security.
本文标签: pluginsWP Job Manager Feature jobs from jobdashboard page
版权声明:本文标题:plugins - WP Job Manager Feature jobs from [job_dashboard] page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745638262a2667693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论