Forum Replies Created

Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter gran3

    (@gran3)

    Thats great! Thanks a lot,
    If you’re ever in Berlin, drop me a line, Ill buy u a beer ??

    Best!

    Thread Starter gran3

    (@gran3)

    Hey Keesiemeijer!

    You did it! All works like a charm now!

    Small recap of what it is doing for future searches.
    Posts use custom start and end date field to sort the archives instead of the standard publishing date.

    @keesiemeijer, could you follow me back on twitter? @modem_studio, then I can donate you something for your work.

    Thread Starter gran3

    (@gran3)

    Hey Keesiemeijer,

    get_locale prints out fr_FR and nl_NL as expected.
    Also $query->set( ‘lang’, ‘nl’ ); should be the correct way of doing it but somehow it doesn’t query correctly,

    when I try

    if($locale === 'fr_FR') {
    	$query->set( 'lang', 'fr' );
    	echo $locale;
    }
    
    if($locale ==='nl_NL') {
    	$query->set( 'lang', 'nl' );
    	echo $locale;
    }

    I get the error Cannot modify header information – headers already sent
    But when the echo is only in one of the if statements it works fine.

    The query on the main page is:

    <?php
    $today = date('Ymd');
    
    $args = array(
    	'post_type' => 'post',
    	'posts_per_page' => 10,
    	'meta_key' => 'event_end_date',
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC',
    	'meta_query' => array(
    	     array(
    	        'key'		=> 'event_end_date',
    	        'compare'	=> '>=',
    	        'value'		=> $today,
    	    )
        ),
    );
    
    $posts = new WP_Query( $args );
    
    if( $posts->have_posts() ) : while ( $posts->have_posts() ) : $posts->the_post(); ?>

    This compares the end date to the current date, and shows all events which are not yet expired.

    Thread Starter gran3

    (@gran3)

    Doesn’t seem to change much. Still both languages are being shown;

    Thread Starter gran3

    (@gran3)

    Once basically creates a post in each language which are linked together, this also means that all the custom fields are saved within each post, those you can however have autofilled so they always match. The query does contain a new query var ‘lang’ to allow the content to be filtered by language.

    Here is some info about it from the plugin author –

    Thread Starter gran3

    (@gran3)

    Im using Polylang for the translation. That link shouldn’t be showing ‘voetbal FR’ only ‘Voetbal’ They are properly linked together. On the main page I use a wp_query and it works correct.

    Thread Starter gran3

    (@gran3)

    Its indeed strange, also the translation doesn’t seem to always work, it works fine, until I update a post, then somehow it shows both languages on the archive. The fact that the dates are a bit mixed up has most likely also something to do with it. But its still does show posts from the correct date.

    it seems that the simple idea of replacing the standard post date with a custom date field (and its functionality) isn’t so easy.

    Thread Starter gran3

    (@gran3)

    Hey Keesiemeijer,

    Thanks a lot! Works like a charm, with some tiny problems. The archives show duplicate posts, these are all of the revisions and autosaves a posts has had. I run it with a plugin called ‘Optimize Database after Deleting Revisions’ which deletes all autosaves and revisions from the data base. Once the website moves over to its final location I will disable this though wp-config (I know this is not recommended but there seems to be no other way), unless there is something I could change on your code? (I’ve placed that into a plugin)

    Also the order doesn’t seem to be working correctly,

    $query->set( 'order', 'ASC' );

    Also some of the Day archives redirect to the 404 page, even tough an event is there. ex https://dev2.modem.ws/nl/2015/1/9 While without the day (9) it works.
    Im having a look at it now and I’ll post if I find something.

    ps: Im from Antwerp as well ?? But live in Berlin for the past 4 years now.
    pss: Ive started following you on twitter with @modem_studio, Ill send u a dm couse Id like to donate you something for you effort ??

    Hi Robbiegod,

    Thanks a lot, would be nice to see how thats done.

    A happy (late) thanksgiving to you to!

    Thread Starter gran3

    (@gran3)

    Thanks a lot, I think its getting somewhere

    the archive /2014 now shows the correct posts also the archive /2014/11 shows all the posts that happen in november, even if the end date is in 2015. So that is all very good.

    Only when I add a day and go to 2014/11/25 it gets the 404 page instead of the days archive, it even skips the date.php’s else statement. This also happens with any other archive page, only /2014 and /2014/11 seem to work.

    Perhaps this has something to do with the fact that all the posts where written in november 2014?

    I have changed all the code to use ‘event_start_date’ and ‘event_end_date’ as meta key.

    I have already looked at many event plugins but they all see very bloated, the only thing I’d like to do is filter out the posts by a custom field date with a simple select box and have a url for each archive.

    The function is still the same, only the date.php now has

    <?php
    // check if we're on a date archive
    if ( is_date() ) {
    
    	//check what type of date archive we are on and if query vars are available
    	$m = ( get_query_var( 'm' ) ) ? get_query_var( 'm' ) : false;
    
    	$year = ( get_query_var( 'year' ) ) ? get_query_var( 'year' ) : false;
    	$month = ( get_query_var( 'monthnum' ) ) ? zeroise( get_query_var( 'monthnum' ), 2 ) : false;
    	$day = ( get_query_var( 'day' ) ) ? get_query_var( 'day' ) : false;
    
    	if ( $m ) {
    		// Custom permalinks structure is not enabled
    		switch ( strlen( $m ) ) {
    		case 4: // Yearly
    			$year = substr( $m, 0, 4 );
    			break;
    		case 6: // Monthly
    			$year = substr( $m, 0, 4 );
    			$month = substr( $m, 4, 2 );
    			break;
    		case 8: // Daily
    			$year = substr( $m, 0, 4 );
    			$month = substr( $m, 4, 2 );
    			$day = substr( $m, 6, 2 );
    			break;
    		}
    	}
    
    	if ( is_year() && $year ) {
    		$start_date = $year . '0101';
    		$end_date   = $year . '1231';
    	}
    
    	if ( is_month() && $year && $month ) {
    		$start_date =  $year . $month . '01';
    		$end_date   =  date( 'Ymt', mktime( 23, 59, 59, $month, 1, $year ) ); // 't' gets the last day
    	}
    
    	if ( is_day() && $year && $month && $day ) {
    		$start_date =  $year . $month . $day;
    		$end_date   =  $start;
    	}
    
    	// your query here
    
    	add_filter( 'get_meta_sql', 'get_meta_sql_date', 10, 2 );
    
    	$args = array(
    		'post_type' => 'post',
    		'posts_per_page' => 10,
    		'meta_query' => array(
    	    'relation' => 'AND',
    	        array(
    	            'key'       => 'event_start_date',
    	            'compare'   => '>=',
    	            'value'     => $start_date,
    	            'type'      => 'DATE'
    	        ),
    	        array(
    	            'key'       => 'event_end_date',
    	            'compare'   => '<=',
    	            'value'     => $end_date,
    	            'type'      => 'DATE'
    	        )
    	    ),
    	);
    
    	$posts = new WP_Query( $args );
    
    	remove_filter( 'get_meta_sql', 'get_meta_sql_date', 10, 2 );
    
    	if( $posts->have_posts() ) :  while ( $posts->have_posts() ) : $posts->the_post(); ?>

    If there is any way of Paying for your time spent I’d be happy to ??

    I see you’re Dutch, I’m Belgian ?? but lets keep it in English so others could use this thread to.

    Thanks!

    Thread Starter gran3

    (@gran3)

    Hey Keesiemeijer,

    Thanks a lot for your fast response.

    I have a start_date and an end_date, so some events can span multiple months. In case an event only takes one day, I only use the end_date

    I have added the code above the one I had in archive.php, which now looks like this

    <?php
    // check if we're on a date archive
    if ( is_date() ) {
    
    	//check what type of date archive we are on and if query vars are available
    	$m = ( get_query_var( 'm' ) ) ? get_query_var( 'm' ) : false;
    
    	$year = ( get_query_var( 'year' ) ) ? get_query_var( 'year' ) : false;
    	$month = ( get_query_var( 'monthnum' ) ) ? zeroise( get_query_var( 'monthnum' ), 2 ) : false;
    	$day = ( get_query_var( 'day' ) ) ? get_query_var( 'day' ) : false;
    
    	if ( $m ) {
    		// Custom permalinks structure is not enabled
    		switch ( strlen( $m ) ) {
    		case 4: // Yearly
    			$year = substr( $m, 0, 4 );
    			break;
    		case 6: // Monthly
    			$year = substr( $m, 0, 4 );
    			$month = substr( $m, 4, 2 );
    			break;
    		case 8: // Daily
    			$year = substr( $m, 0, 4 );
    			$month = substr( $m, 4, 2 );
    			$day = substr( $m, 6, 2 );
    			break;
    		}
    	}
    
    	if ( is_year() && $year ) {
    		$start_date = $year . '0101';
    		$end_date   = $year . '1231';
    	}
    
    	if ( is_month() && $year && $month ) {
    		$start_date =  $year . $month . '01';
    		$end_date   =  date( 'Ymt', mktime( 23, 59, 59, $month, 1, $year ) ); // 't' gets the last day
    	}
    
    	if ( is_day() && $year && $month && $day ) {
    		$start_date =  $year . $month . $day;
    		$end_date   =  $start;
    	}
    
    	// your query here
    
    	$args = array(
    		'post_type' => 'post',
    		'posts_per_page' => 10,
    		'meta_key' => 'end_date',
    		'orderby' => 'meta_value_num',
    		'order' => 'ASC',
    		'meta_query' => array(
    	    'relation' => 'AND',
    	        array(
    	            'key'       => 'event_start_date',
    	            'compare'   => '>=',
    	            'value'     => $start_date,
    	            'type'      => 'DATE'
    	        ),
    	        array(
    	            'key'       => 'event_end_date',
    	            'compare'   => '<=',
    	            'value'     => $end_date,
    	            'type'      => 'DATE'
    	        )
    	    ),
    	);
    
    	$posts = new WP_Query( $args );
    
    	if( $posts->have_posts() ) :  while ( $posts->have_posts() ) : $posts->the_post(); ?>

    But when I go to dev2.modem.ws/2014 I only get three posts, and when I go to dev2.modem.ws/2014/11 I only get one. The select menu there doesn’t work yet, the urls still need to be changed.

    Would it make more sense to make a custom archive page? or is archive.php the correct place to be in order to change which posts gets filtered out.

    @robbiegod, thanks a lot for this question

    I’ve run into the same issue and came across your hunt for a solution on different sites ??

    Im trying to do exactly the same thing and was wondering if you could also share the ‘Event List Widget’ you refer to. Im looking for a way to sort out entries by year, month, day through a select dropdown, but without succes. What would the urls for these pages look like? The standard archive pages like https://www.website.com/2014/11 doesn’t seem to get me far

    I don’t use custom post so I have the query in my archive.php with following code:

    <?php
    add_filter( 'get_meta_sql', 'get_meta_sql_date', 10, 2 );
    
    $args = array(
    	'post_type' => 'post',
    	'posts_per_page' => 4=10,
    	'meta_key' => 'end_date',
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC',
    	'meta_query' => array(
        'relation' => 'AND',
        array(
            'key'       => 'start_date',
            'compare'   => '>=',
            'value'     => '20140601',
            'type'      => 'DATE'
        ),
        array(
            'key'       => 'end_date',
            'compare'   => '<=',
            'value'     => '20140630',
            'type'      => 'DATE'
        )
    ),
    );
    
    $posts = new WP_Query( $args );
    
    remove_filter( 'get_meta_sql', 'get_meta_sql_date', 10, 2 );
    
    if( $posts->have_posts() ) :
    ?>

    Also my guess is that the ‘value’ fields there should have some dynamic content instead of a fixed value. I’m trying to wrap my head around it but without much result ??

    Would it be possible to break down the code a bit for me including the filter method?

    I have a small test version on dev2.modem.ws

    Very much appreciated!

    All the best,

    works for me, great
    If I come across something strange I’ll let you know

    Thanks a lot!

    Did you find any answers yet?
    I’m having the exact same problem. About 80% of the time I get “Tumblr returned an HTTP Status Code of 500”, could this have something to do with server permissions?

Viewing 14 replies - 1 through 14 (of 14 total)