Navigazione

    Privacy - Termini e condizioni
    © 2020 Search On Media Group S.r.l.
    • Registrati
    • Accedi
    • CATEGORIES
    • Discussioni
    • Non letti
    • Recenti
    • Hashtags
    • Popolare
    • Utenti
    • Stream
    • Interest
    • Categories
    1. Home
    2. pagineverdi
    3. Post
    P

    pagineverdi

    @pagineverdi

    • Profilo
    • Chi segue 0
    • Da chi è seguito 0
    • Discussioni 1
    • Post 2
    • Migliore 0
    • Gruppi 0
    Iscrizione Ultimo Accesso
    Località Palermo Età 45
    0
    Reputazione
    2
    Post
    0
    Visite al profilo
    0
    Da chi è seguito
    0
    Chi segue
    User Newbie

    Post creati da pagineverdi

    • RE: Da MYSQL a WORDPRESS

      Intanto Grazie per l'intervento, avevo già visto quanto da te linkato, e sono veramente vicino alla soluzione infatti questa è la query a cui sono arrivato

      
      SELECT 
          wp_posts.* 
      FROM 
      wp_posts 
      INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
      LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) 
      LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' ) 
      WHERE 1=1 AND 
      ( wp_term_relationships.term_taxonomy_id IN (2159) ) AND 
      ( ( wp_postmeta.meta_key = 'dir_featured' AND CAST(wp_postmeta.meta_value AS CHAR) = 'yes' ) OR mt1.post_id IS NULL ) AND wp_posts.post_type = 'ait-dir-item' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID 
      ORDER BY 
      wp_postmeta.meta_value DESC, 
      wp_posts.post_date DESC
      
      

      mentre devo arrivare a questa

      SELECT
      **    IF(wp_postmeta.meta_value = 'yes',post_date,'zz') as mv,**
          wp_posts.*
      FROM wp_posts
      INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
      LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
      LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' )
      WHERE
      ( wp_term_relationships.term_taxonomy_id IN (".$queried_object ->term_id.") ) AND
      ( ( wp_postmeta.meta_key = 'dir_featured' AND CAST(wp_postmeta.meta_value AS CHAR) = 'yes' ) OR mt1.post_id IS NULL ) AND
      wp_posts.post_type = 'ait-dir-item' AND
      wp_posts.post_status = 'publish'
      GROUP BY
      wp_posts.ID
      ORDER BY
      **mv ASC,**
      wp_posts.post_date DESC
      

      in grassetto ho messo cosa cambia fra le 2.

      avevo percorso la strada di utilizzare direttamente la query sul codice, ma mi serve il risultato come lo restituisce ik WP_Query visto il codice già esistente, andarlo a stravolgere non sarebbe proprio il caso.

      quì i parametri utilizzati fino ad ora

          $params = array(
              'post_type'            => 'ait-dir-item',
              'nopaging'            =>    true,
              'meta_query' => array(
                  'relation' => 'OR',
                      array(
                          'key' => 'dir_featured',
                          'value' => 'yes',
                          'compare' => '='
                      ), 
                      array(
                          'key' => 'dir_featured',
                          'value' => '',
                          'compare' => 'NOT EXISTS'
                      )
                  )    ,
              'orderby'             => array( 'dir_featured' => 'DESC','post_date' => 'DESC'  ),
              'post_status'        => 'publish',
              'tag__in'            => $queried_object ->term_id
          );
      

      Grazie ancora attendo info 🙂

      postato in CMS & Piattaforme Self-Hosted
      P
      pagineverdi
    • Da MYSQL a WORDPRESS

      Salve a tutti,
      stò modificando delle funzioni di un tema premium acquistato di themeforest e stò avendo qualche problema con una query.

      Io ho questo codice:

      [PHP]
      function getItemTag($tag) {

      $queried_object = get_queried_object();

      $params = array(
      'post_type' => 'ait-dir-item',
      'nopaging' => true,
      'meta_query' => array(
      'relation' => 'OR',
      array(
      'key' => 'dir_featured',
      'value' => 'yes',
      'compare' => '='
      ),
      array(
      'key' => 'dir_featured',
      'value' => '',
      'compare' => 'NOT EXISTS'
      )
      ) ,
      'orderby' => array( 'dir_featured' => 'DESC','post_date' => 'DESC' ),
      'post_status' => 'publish',
      'tag__in' => $queried_object ->term_id
      );

      $itemsQuery = new WP_Query();
      $items = $itemsQuery->query($params);

      foreach ($items as $key => $item) {
      // options
      $item->optionsDir = get_post_meta($item->ID, '_ait-dir-item', true);

      // link
      $item->link = get_permalink($item->ID);
      // thumbnail
      $image = wp_get_attachment_image_src( get_post_thumbnail_id($item->ID), 'full' );
      if($image !== false){
      $item->thumbnailDir = $image[0];
      } else {
      $item->thumbnailDir = $GLOBALS['aitThemeOptions']->directory->defaultItemImage;
      }
      // marker
      $terms = wp_get_post_terms($item->ID, 'ait-dir-item-category');
      $termMarker = $GLOBALS['aitThemeOptions']->directoryMap->defaultMapMarkerImage;
      if(isset($terms[0])){
      $termMarker = getCategoryMeta("marker", intval($terms[0]->term_id));
      }
      $item->marker = $termMarker;
      // excerpt
      $item->excerptDir = aitGetPostExcerpt($item->post_excerpt,$item->post_content);
      // package class
      $item->packageClass = getItemPackageClass($item->post_author);
      // rating
      $item->rating = get_post_meta( $item->ID, 'rating', true );

      }

      return $items;

      }
      [/PHP]

      che mi da dei risultati in ordine sbagliato rispetto a come li vorrei. Ho trovato in Mysql la soluzione con la seguente query

      
      
      SELECT
      IF(wp_postmeta.meta_value = 'yes',post_date,'zz') as mv,
      wp_posts.*
      FROM wp_posts
      INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
      LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
      LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' )
      WHERE
      ( wp_term_relationships.term_taxonomy_id IN (".$queried_object ->term_id.") ) AND
      ( ( wp_postmeta.meta_key = 'dir_featured' AND CAST(wp_postmeta.meta_value AS CHAR) = 'yes' ) OR mt1.post_id IS NULL ) AND
      wp_posts.post_type = 'ait-dir-item' AND
      wp_posts.post_status = 'publish'
      GROUP BY
      wp_posts.ID
      ORDER BY
      mv ASC,
      DATE_FORMAT(wp_posts.post_date,'%Y-%m-%d') DESC
      "
      
      

      dove $queried_object è il risultato di "$queried_object = get_queried_object();" utile per prendermi dei dati che mi servono.

      Come posso utilizzare questa query nella funzione sopra riportata?? è possibile parametrizzare la query per utilizzare i metodi

      nativi di wordpress per ricavarne i risultati? Vorrei avere lo stesso risultato in entrambi i casi così da non dover modificare

      ulteriormente il codice di stampa per i risultati...

      Grazie in anticipo, saluti.

      postato in CMS & Piattaforme Self-Hosted
      P
      pagineverdi