• Ben

    (@asdfasdfasdfasdf)


    Hi,

    I have an instance where I need to do a search and find out if a category is equal to the current month, then display a loop. I’m imagining it might look something like

    if(‘category’ == date(F)) { loop }

    But I’m really not strong at all in php. I’m sure this is something really simple, hopefully.

    Any help doing this would be appreciated.

    Thanks in advance,

    -ben

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Ben

    (@asdfasdfasdfasdf)

    you can see what i’m doing here: https://laliberteonline.com
    notice ‘marks schedule’. right now i have it displaying the current month, but when next month comes along I’ll have to change it.

    <?php
    		$args = array('post_type'=>'marks-schedule','category_name'=>'July','posts_per_page'=>4,);
    			$the_query = new WP_Query( $args );
    			// The Loop
    			while ( $the_query->have_posts() ) : $the_query->the_post();
    				//variables
    				$permalink = get_permalink();
    				$title = get_the_title();
    				$img = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
    				echo '<span class="date-range">';
    				the_field('days');
    				echo '</span>';
    				echo '<p>';
    				echo  $title;
    				echo '';
    				the_field('event_type');
    				echo '</p>';
    				endwhile;
    ?>

    So like I said, what I really want is to use php to determine which category matches the current month and then to display all the information listed above.

    Anyone?

    [Moderator Note: Please post code or markup snippets between backticks or use the code button.]

    If u have a category for each month , u can try saving the value of date(‘F’) in a variable and sending it directly to the query .

    Thread Starter Ben

    (@asdfasdfasdfasdf)

    Thanks for the speedy reply! Could you provide an example of what this might look like? Sorry I’m not that good with writing code from scratch..

    Try adding this :

    $_month = date('F');
    $args = array('post_type'=>'marks-schedule','category_name'=>$_month ,'posts_per_page'=>4,);

    and the rest will be the same .

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search categories to find if one is equal to month and then display content’ is closed to new replies.