plugins - WP Job Manager Feature jobs from [job_dashboard] page

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

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 question

I'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 question

I'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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Short 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745638262a4637528.html

相关推荐

  • plugins - WP Job Manager Feature jobs from [job_dashboard] page

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信