skip to Main Content

I have a post list-

<?php
$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'category_name' => 'job',
    'posts_per_page' => 20,
    'order' => 'ASC',
);
$arr_posts = new WP_Query( $args );

if ( $arr_posts->have_posts() ) :

    while ( $arr_posts->have_posts() ) :
        $arr_posts->the_post();
        ?>

<div class="row">
    <div class="col-md-5">
        <?php
            if ( has_post_thumbnail() ) :
                the_post_thumbnail();
            endif;
        ?>
    </div>
    <div class="col-md-7 p-0" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <h3><?php the_title(); ?></h3>
        <p><?php the_content(); ?></p>
        <a class="btn btn-blue" title="Read The Coverage" href="https://localhost/fmoc/apply-for-job/" target="_blank" rel="noopener">Apply Now</a>
    </div>
        </div>
        <?php
    endwhile;
    wp_reset_postdata();
endif; ?>

My all post are redirect on a same page which is an another custom template page. I want the post title on that page. How can I do this.
enter image description here

2

Answers


  1. You can add post title in url parameter.

    <a class="btn btn-blue" title="Read The Coverage" href="https://localhost/fmoc/apply-for-job?post_title=<?php the_title(); ?>" target="_blank" rel="noopener">Apply Now</a>
    

    In other page you will get that parameter in $_REQUEST[‘post_title’].

    Login or Signup to reply.
  2. My proposal is similar to @VimalUsadadiya, but instead of the entire title, I would only add the post ID.

    Values before inserting into URL should be escaped, so if you want to insert post title use urlencode() function

    <p><?php the_content(); ?></p>
    <?php
    
       $job_id = get_the_ID();        // current post ID
       $url = home_url('/fmoc/apply-for-job');
       $url .= sprintf('?jobid=%d', $job_id);
    
    ?><a class="btn btn-blue" title="Read The Coverage" 
         href="<?php echo $url; ?>" target="_blank" rel="noopener">Apply Now</a>
    

    On the form page, get ID from url, check it and display the title of the corresponding post:

    $title = '';
    if ( isset($_GET['jobid']) && is_numeric($_GET['jobid']) ) {
        $id = (int)$_GET['jobid'];
        $title = get_the_title($id);
    }
    
    echo esc_html($title);
    

    References:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search