最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin6PV0评论
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.

Post a comment

comment list (0)

  1. No comments so far