Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9063331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:58:16+00:00 2026-06-16T15:58:16+00:00

I have a question about being able to get values out of the hidden

  • 0

I have a question about being able to get values out of the hidden input boxes in this:

<?php  $i = 0; $j = 1;?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php get_template_part( 'content', get_post_format() ); 
        $postid[$i] = get_the_ID();
        echo "<input type='hidden' value='".$postid[$i]."' id='hiddenpostitle".$j."' name='hiddenpostitle'/> ";
        echo "<input type='hidden' value='".$j."' id='hiddenpostnumfield".$j."'/> ";            
    ?>
    <?php 
        $i++;
        $j++;
    ?>
<?php endwhile; endif; ?>

So what this does is draw in all the post and formats them according to WordPress. While each post is looped I create 2 input boxes for each, one with the post id with a incremental variable and one that stores the value of the above input box with an incremental variable. I am making a product overview so I need to be able to access the proper post and have that sent using JSON.

The part that I am stuck on is the getting the correct post type that was clicked.

Here is my JQuery code so far:

<script type="text/javascript">
$(function () {
    $('.item-post a').each(function (i) {
        $(this).on("click", function (e) {
            alert(i);

            var num = $('#hiddenpostitle').val();
            alert(num);

            var prodname = $('#hiddenpostitle' + num /* + (i+1)*/).val();

            $.post('overviewcheck-515adfzx8522', {'ProdName': prodname}, function (response) { }, 'json');
        });
    });
    $('.item-post a').colorbox({ opacity: 0.3, href: "../overviewa512454dzdtfa" });
});
</script>   

This is not working properly because it will always give me the first post there is because I am not getting the associated product that was clicked.

Example: lets say you click 3 and 1 is first, you will always get 1 even if you click 2 or 3 or 4.

I am really stuck and need help on this. Not to sure how to proceed.

Merry Christmas!

UPDATE:

new Code being used

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="post-id-holder">
      <?php get_template_part('content',get_post_format()); ?>
      <div class="post-id-data" post-id="<?php echo get_the_ID(); ?>" post-title="something"></div>
      </div>                        

    <?php endwhile; endif; ?>
<script type="text/javascript">
(document).ready(function() {
   $('.item-post a').click(function(){
    // find the article for the post
    var article  = $(this).parentsUntil('article').parent();
    var post_id = article.attr("id");
    var post_title $('.entry-title a',article).text();
    alert(post_id);
    alert(post_title);


    $.post('overviewcheck-515adfzx8522', 
    { 
    'ProdName': prodname

    },
    function(response) {
    },
    'json'
    );


   $('.item-post a').colorbox({opacity:0.3, href:"../overviewa512454dzdtfa"});
   });
});

ANSWER:

Thanks Matt! 🙂

Here is the code, so if you ever run into this you can use it!

WordPress Queried section:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <div class="post-id-holder">
 <?php get_template_part('content',get_post_format()); ?>
  <div class="post-id-data" post-id="<?php echo get_the_ID(); ?>" post-title="something">      </div> 
 </div>                     

<?php endwhile; endif; ?>

JQuery Side:

<script type="text/javascript">
$(document).ready(function() {
 $('.item-post a').click(function(){
    // find the article for the post
        var article  = $(this).parentsUntil('article').parent();
    var post_id = article.attr("id");
    var post_title = $('.entry-title a',article).text();



        $.post('overviewcheck-515adfzx8522', 
                                        { 
        'ProdName': post_title

                                        },
         function(response) {
                                        },
         'json'
        );



       });
    $('.item-post a').colorbox({opacity:0.3, href:"../overviewa512454dzdtfa"});
});

</script>

Again thanks everyone! Merry Christmas!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:58:18+00:00Added an answer on June 16, 2026 at 3:58 pm

    There really isn’t a need to use an input tag if you are not creating a form. It will just cause issues if by chance your code is executed inside a form block. If you just want to discover the post-id at javascript time, then it’s better to stuff it into a property of a div or span tag.

    <?php while(have_posts()): ?>
    <?php the_post(); ?>
    <div class="post-id-holder">
        <?php get_template_part('content',get_post_format()); ?>
        <div class="post-id-data" post-id="<?php echo get_the_ID(); ?>" post-title="something"></div>
    </div>
    <?php endwhile; ?>
    

    Later you can access it via javascript as such.

    <script type="text/javascript">
    $(document).ready(function() {
       $('.item-post a').click(function(){
          // where are we? we are at any link inside the post, and that's no good.
    
          // find the holder parent
          var holder = $(this).parentsUntil('.post-id-holder');
          var data = $(".post-id-data",holder);
    
          var post_id = data.attr("post-id");
          var post_title = data.attr("post-title");
       });
    });
    </script>
    

    EDIT:

    After reviewing the HTML, I think you can get the post ID and title without having to add anything to the template.

    <script type="text/javascript">
    $(document).ready(function() {
       $('.item-post a').click(function(){
          // find the article for the post
          var article  = $(this).parentsUntil('article').parent();
          var post_id = article.attr("id");
          var post_title $('.entry-title a',article).text();
          alert(post_id);
          alert(post_title);
       });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the first question I have found myself not being able to get
Here is another question I have about being able to calculate this scenario in
I have question about XSLT1.0. The task is to write out in HTML all
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
I have a question about SqlDataReader: Is there some way to modificated the values
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,
i have question about YAJLiOS parser... I have next json data : {{ body

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.