Forum Replies Created

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter Astilla VGR

    (@astilla222)

    It is needed to add “WPCF-” before the name slug.

    function my_pre_get_posts( $query ) {

    $query->set(‘orderby’, ‘meta_value’);
    $query->set(‘meta_key’, ‘wpcf-fecha’);
    $query->set(‘meta_type’, ‘date’);
    $query->set(‘order’, ‘ASC’);

    // return
    return $query;

    }

    add_action(‘pre_get_posts’, ‘my_pre_get_posts’);

    Thread Starter Astilla VGR

    (@astilla222)

    The best option is not to create a Div for each “line”, so it is not needed to open-close en each line.

    Thread Starter Astilla VGR

    (@astilla222)

    THE MAIN ISSUE: It is needed to add “WPCF-” before the custom field slug.

    Thread Starter Astilla VGR

    (@astilla222)

    @quinini have a view on this post please.

    Thread Starter Astilla VGR

    (@astilla222)

    Im having the same issue with a field where I add a Spotify embed code. Here I have the same issue with Wikiloc embed code. Could it be related with html code inserctions in text custom fields?

    Thread Starter Astilla VGR

    (@astilla222)

    Thanks! Here the result:
    SELECT SQL_CALC_FOUND_ROWS lm_posts.ID FROM lm_posts WHERE 1=1 AND lm_posts.post_type = ‘programada’ AND (lm_posts.post_status = ‘publish’) ORDER BY lm_posts.post_date DESC LIMIT 0, 10

    It seems that it is not ordering by date custom field instead it is using post_date. No idea where is the issue…any advice?

    Thread Starter Astilla VGR

    (@astilla222)

    Hi @bcworkz! Im back to this issue.

    Here my functions.php as it is right now:

    
    <?php
    function my_theme_enqueue_styles() {
    
        $parent_style = 'foundation-css-framework'; // This is 'foundation-css-framework' child theme.
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'clubcotacero',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style ),
            wp_get_theme()->get('Version')
        );
    }
    
    function my_pre_get_posts( $query ) {
             
            $query->set('orderby', 'meta_value');   
            $query->set('meta_key', 'fecha');   
            $query->set('order', 'ASC'); 
            
        // return
        return $query;
    
    }
    
    /*add_action('pre_get_posts', 'my_pre_get_posts');*/
    
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    ?>
    

    And here my archive.php file:

    
    <?php
    /**
     * The template for displaying archive pages
     *
     * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/
     *
     * @package Foundation_CSS_framework
     */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area large-12 medium-8 small-12 cell grid-x">
    		<main id="main" class="site-main">
    
    		<?php
    		if ( have_posts() ) : ?>
    
    			<header class="page-header large-12 cell">
    				<h1 class="page-title"> Activdades Programadas </h1>
    				<?php
    					the_archive_description( '<div class="archive-description">', '</div>' );
    				?>
    			</header><!-- .page-header -->
    
    			<?php
    			/* Start the Loop */
    
    			/* Mirando el resultado de la busqueda */
    			
    			/**/
    
    			while ( have_posts() ) : the_post();
    
    				/*
    				 * Llamamos a nuestro propio content solo para listas
    				 */
    
    				get_template_part( 'template-parts/content-programada-lista', get_post_format() );
    
    			endwhile;
    
    			the_posts_navigation();
    
    		else :
    
    			get_template_part( 'template-parts/content', 'none' );
    
    		endif; ?>
    
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php
    get_sidebar();
    get_footer();
    

    I tryed to paste in the code your line:
    <?php echo get_queried_object()->request;

    But obviously it is not a “copy/paste” solution. I have this:
    Notice: Undefined property: WP_Post_Type::$request in C:\xampp\htdocs\testeo\wp-content\themes\clubcotacero\archive-programada.php on line 42

    So I assume I have to change “->request”. Could you please shed some light on this? It would be really appreciated.

    Kind Regards
    VíctorR

    • This reply was modified 5 years, 12 months ago by Astilla VGR.
    Thread Starter Astilla VGR

    (@astilla222)

    Hi @bcworkz Indeed i worked in the posted link and once you checked it it was already solved. BUT YES! I really appreciate your advice coding.

    My main issue, to use a loop, is that I do not uderstand how to deal with “open the line” “close the line”. I suposse I need to include a conditional rule so if it is 0 module division I have to include “open line” and if it is 2 module division (let say we want 3 rows) I have to include “close line”.

    If I am in the right way, could you suggest a codification guide lines or a little example?

    Thanks in advance. Make it works its ok, but to have an efficient and elegant code makes me happy ??

    Thread Starter Astilla VGR

    (@astilla222)

    It is really strange, because the following code works

    function my_pre_get_posts( $query ) {
             
            $query->set('orderby', 'meta_value');   
            $query->set('order', 'ASC'); 
            
        // return
        return $query;
    
    }

    But the folliwn one, not:

    function my_pre_get_posts( $query ) {
             
            $query->set('orderby', 'meta_value');   
            $query->set('meta_key', 'fecha');   
            $query->set('order', 'ASC'); 
            
        // return
        return $query;
    
    }

    Why if I introduce $query->set('meta_key', 'fecha'); it does returns and empty query?

    Thread Starter Astilla VGR

    (@astilla222)

    Hi @bcworkz, @joyously, now it works ??

    Thanks a lot for your help.

    Thread Starter Astilla VGR

    (@astilla222)

    Hi @bcworkz thanks for your feedback! Indeed my idea is to user it as an organizational tool and maybe to use it in multiple cases in advance.

    Do you know what is wrong in my code? The template part is not being loaded.

    Thread Starter Astilla VGR

    (@astilla222)

    I assume these are the variables to be updated:

    
    $query->set('orderby', 'meta_value');	
    $query->set('meta_key', 'start_date');	 
    $query->set('order', 'DESC'); 
    

    if programada custom post type should be order descent by fecha custom field:

    
    $query->set('orderby', '*****');	
    $query->set('meta_key', 'fecha');	 
    $query->set('order', 'DESC');
    

    What should be the value for meta_value? are the other variables ok?

    Thread Starter Astilla VGR

    (@astilla222)

    Is this more accurate example?

    
    <?php
    
    function my_pre_get_posts( $query ) {
    	
    	// do not modify queries in the admin
    	if( is_admin() ) {
    		
    		return $query;
    		
    	}
    	
    
    	// only modify queries for 'event' post type
    	if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'event' ) {
    		
    		$query->set('orderby', 'meta_value');	
    		$query->set('meta_key', 'start_date');	 
    		$query->set('order', 'DESC'); 
    		
    	}
    	
    
    	// return
    	return $query;
    
    }
    
    add_action('pre_get_posts', 'my_pre_get_posts');
    
    ?>
    Thread Starter Astilla VGR

    (@astilla222)

    @sterndata I have found this (to be added on functions.php)

    function prefix_modify_query_order( $query ) {
      if ( is_main_query() ) {
     
        $args =  array( 'post_date' => 'ASC' );
     
        $query->set( 'orderby', $args );
      }
    }
    add_action( 'pre_get_posts', 'prefix_modify_query_order' );

    Do you think that it could works changin ‘post_date’ to my custom fild date? I will check the documentation you suggest.

    Thread Starter Astilla VGR

    (@astilla222)

    Hi @sterndata! Thanks a lor for your feedback.

    Sorry but I will need some more tips to develope this. If I well undertood, i have to add this to my code:

    <?php add_action( 'pre_get_posts', 'your_function_name' ); ?>

    Then I have to define ‘your_function_name’ in functions file. Right?

    Something like

    function sort_by_date(){
    	
    }

    Sorry for the basic question, but long time not developing…

    Could you give me some guidelines for the function develop?

    Thanks in advance.

Viewing 15 replies - 1 through 15 (of 20 total)