Support » Plugin: Form to Post » Get post by category_name

  • Resolved MBWD

    (@mbwd)


    This is probably simple for advanced users, but I am a bit stuck. I am using the default example that the plugin author provides in Contact Form 7:

    Categories (required) <br/>
      [checkbox* post_category_name "Uncategorized" "Cat1" "Cat2" "Cat3"] <br/>

    I am able to get this working with posts showing up on the blog page. What I would like to do is configure the site so that posts show on different pages based on what category the poster checks off in the checklist. I am using this code straight from the WordPress codex:

    <?php

    $args = array( 'category_name' => 'Cat1' ); 
    
    $myposts = get_posts( $args );
    foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    	<li>
    		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endforeach;
    wp_reset_postdata();?>

    But I am not getting the post to show up on the relevant page. It’s still just showing up on the general blog page. Any help?

    https://wordpress.org/plugins/form-to-post/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    This question is more about where to put your code among your theme’s files. It is not really a question about the plugin itself.

    Thread Starter MBWD

    (@mbwd)

    OK, fair enough, maybe I can rephrase it to be in the context of the plugin. When I make test posts using the example categories that you give, all posts show up in the category of “Uncategorized” rather than in the category to which I have assigned them, even though I have already created that category of post in the site. How can I get them to be assigned to the category selected while filling out the form?

    Plugin Author Michael Simpson

    (@msimpson)

    I tried this on my site and it works OK for me.

    (1) I created “Cat1”, “Cat2”, “Cat3” as categories in Posts -> Categories

    (2) I created a Contact Form 7 form with definition:

    <p>Title:  [text* post_title 20/] </p>
    <p>Category:    [checkbox* post_category_name "Uncategorized" "Cat1" "Cat2" "Cat3"]</p>
    <p>[textarea post_content]</p>
    <p>[submit "Send"]</p>

    (3) I put the CF7 short code in a new post. I viewed the post and made submissions for each of the categories

    (4) I went to Posts in the administration area and verified that 4 new posts were created, and each had the correct Category.

    Thread Starter MBWD

    (@mbwd)

    Thank you. That procedure works. I was leaving out the very first step.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get post by category_name’ is closed to new replies.