admin管理员组

文章数量:1435822

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.

本文标签: pluginsWP Job Manager Feature jobs from jobdashboard page