Home WordPress load posts onClick when posts have specific value in meta_key
Reply: 0

WordPress load posts onClick when posts have specific value in meta_key

user2467
1#
user2467 Published in June 19, 2018, 2:44 pm

On the Create Company page you can insert name, year and version. After you press Save it will save the information together with a generated token to a wordpress post as metadata and the category company. if you click on "show companies" it will load all posts with category company from the current user and put 2 buttons next to it. One button to create a new feedbaack which will be saved in another post with category feedback and another token. and if you press the show feedback it should load all the posts with category feedback and the same token as the one from the created company. so you can make multiple feedback for a company and then show it again on click button.

Test 5, Test 2 and Test 1 are all earlier created companies where i would like to be able to load their specific feedbacks

<div class="show_feedback">
<?php 
// the query
    global $current_user;
    $author_query = array('posts_per_page' => '-1', 'author' => $current_user->ID, 'cat' => '3', 'meta_key' => 'cToken', 'meta_value' => '4IWCTq7OCa3eyxi');
    $wpb_feedback_query = new WP_Query($author_query);
?>
<?php if ( $wpb_feedback_query->have_posts() ) : ?>
<ul>
    <!-- the loop -->
    <?php while ( $wpb_feedback_query->have_posts() ) : $wpb_feedback_query->the_post(); ?>
        <li>
        <?php the_title(); ?>
        </li>
    <?php endwhile; ?>
    <!-- end of the loop -->
</ul>
<?php wp_reset_postdata(); ?>
<?php else : ?>
    <?php _e( 'Sorry, no posts matched your criteria.' ); ?>
<?php endif; ?>
</div>

this code is what i have so far but at the moment the meta_value is static but should be different for each of the posts before.

function startFeedback(postId){
    $.ajax({
        type: "POST",
        url: ajax_object.ajax_url,
        data:{
        action:'create_feedback', 
        postId: postId,
        eFirstName: $("#eFirstName").val(), 
        eLastName: $("#eLastName").val(),
        eDepartment: $("#eDepartment").val()
        },
        success:function(response) {
        $("#result").html(response);
        }
    });
}

function showFeedback(postId){
    $(".show_company").hide();
    $(".show_feedback").show();
}

thats the onclick handler which is showing the hidden class to show the post loop

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.564816 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO