Forum Replies Created

Viewing 15 replies - 16 through 30 (of 44 total)
  • Thread Starter portia79

    (@portia79)

    That’s working perfectly. Thank you.

    Thread Starter portia79

    (@portia79)

    Thank you both. I’ve been looking at the code in other plugins but have not made much sense.

    bcworks – I’m not sure I understand your middle paragraph. I’ve done what you recommended in the first paragraph but for the second I’m a bit confused:

    <?php
    global $wpdb;
    $limit = 0;
    $year_prev = null;
    $months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month ,  YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'news' GROUP BY month , year ORDER BY post_date DESC");
    ?>
    <div class="menu">
        <ul>
        <?php
        foreach($months as $month) :
            $year_current = $month->year;
            if ($year_current != $year_prev){
                if ($year_prev != null){
    
                } ?>
                <li><a href="<?php bloginfo('url') ?>/news/<?php echo $month->year; ?>/"><?php echo $month->year; ?></a>
                    <ul>
                    <?php } ?>
                        <li>
                            <a href="<?php bloginfo('url') ?>/news/<?php echo $month->year; ?>/<?php echo date("m", mktime(0, 0, 0, $month->month, 1, $month->year)) ?>"><span class="archive-month"><?php echo date_i18n("F", mktime(0, 0, 0, $month->month, 1, $month->year)) ?> (<?php echo $month->post_count; ?>)</span></a>
                        </li>
                    <?php $year_prev = $year_current; ?>
                    </ul>
                </li> <?php endforeach; ?>
    
        </ul>
    </div>
    Thread Starter portia79

    (@portia79)

    Thank you. That was it!!!

    Thread Starter portia79

    (@portia79)

    Hi,

    Thank you, however, that has not solved the problem. ??

    Am really puzzled why it does not pick up taxonomy-news_tax.php

    Thread Starter portia79

    (@portia79)

    Ok. Thanks.

    Thread Starter portia79

    (@portia79)

    Thanks a lot. That’s a lot of good food for thought.

    I’m not going to manipulate the tables directly in phpmyadmin then.

    I’m going to read on hooks now. I’ve seen this term a few times but have not got to read on it yet. Now it’s a good time to do it.

    Thanks for the clarification on the use of admin-post.php.

    Now, in view of what you’ve written above perhaps I was too quick to decide to move the posts of category ‘events’ to a custom post type (‘events’).
    Could you confirm if it’s possible to have a monthly post archive for certain categories only? What I mean by a ‘post archive’ is a clickable list of months where posts were published, eg;

    January 2019 (9 posts)
    February 2019 (3 posts)
    March 2019 (23 posts)

    But only for the posts of a category ‘events’?

    Thank you again.

    Thread Starter portia79

    (@portia79)

    Thanks. That’s brilliant. I’m learning more and more about how it all really works.

    I have logged in to phpmyadmin on my testing wordpress installation and looked at the wp_posts table. I’ve changed the post type from ‘post’ to ‘events’ (custom post type) and it worked fine.

    Now, apart from the post_type I cannot see any field in that table that would reference assigned post categories. Am I missing something? I was hoping to do a bulk SQL statement. The one I did was limited to WHERE ID=xxxx, which obviously referred to the single post I referenced.

    In terms of adding a custom post type, wouldn’t I be better off creating a custom taxonomy so that the category terms are separate between standard posts and custom posts?

    I’d like to try the wp_update_post method as well. Which part of admin-post.php should I put the code? Can it be done at the very end after all the existing content?

    Also, would something like that be ok:

     $args = array(
         'category_name' => 'Events'
     );
     $the_query = new WP_Query( $args );
    
     // The Loop
     if ( $the_query->have_posts() ) {
    
        while ( $the_query->have_posts() ) {
    
           $my_post = array(
          'post_type'   => 'events',
         );
         wp_update_post( $my_post );
        }
     }
    Thread Starter portia79

    (@portia79)

    OK. I’m stuck again. I seem to be able to insert posts but, now everytime the code is executed, the same posts get added resulting in multiple duplicates.

    1. First of all, just to clarify, I’m adding all this code in a page template. Eventually, the page will display those ‘events’ in a nice fashion. I assume, none of the code should go to functions.php? The code below just lists the posts/events in a simple list for the sake of testing (and inserts them to the WP database).
    2. How do I prevent them from re-inserting each time the page is refreshed. The only unique thing is a post/event id (a string like ‘k3afke2kr’), which can be accessed in the code below via $event[‘id’]. Even the ‘title’ might not be unique as there are weekly/monthly events of the same title.

    <?php 
      $request = wp_remote_get( 'https://api.riderhq.com/api/v1/3446/getevents?pretty=true' );
      
      if( is_wp_error( $request ) ) {
        echo "wrong request";
        return false; // Bail early
      }
      
      function utf8ize($mixed) { 
        if (is_array($mixed)) { 
        foreach ($mixed as $key => $value) { 
        $mixed[$key] = utf8ize($value); 
        } 
        } else if (is_string ($mixed)) { 
        return utf8_encode($mixed); 
        } 
        return $mixed; 
        }
      
      $body = wp_remote_retrieve_body( $request ); 
      $data = json_decode(utf8ize($body), true); 
      $data_events = $data['events'];
      print_r($data_events); // prints ok -
    
      if( ! empty( $data_events ) ) {
        echo '<ul>';
    	    foreach( $data_events as $event ) {
           
            echo '<li>';
            echo $event['id'];
    			    echo '<a href="' . esc_url( $event['uri'] ) . '">' . $event['name'] . '</a>';
            echo '</li>';
    
            $new_post = array(
              'post_title' => $event['name'],
              'post_content' => 'description',
              'post_status' => 'publish',
              'post_author' => '2',
              'post_type' => 'post',
              'post_category' => array(1),
          );
          wp_insert_post($new_post);
    
        
    	    }
    	  echo '</ul>';
      }
    
    ?>

    Thank you very much for the support.

    Thread Starter portia79

    (@portia79)

    Thank you. I’ve managed to rewrite it to get the data using php as per the article you linked. Now, I’ll attempt to put all the pieces together and will report once/if done:)

    Thread Starter portia79

    (@portia79)

    Thank you for your reply @sjaure.

    Your understanding of my situation is correct (apart from the fact that Site A is not a WP site – but in this case, it shouldn’t matter, should it?). When you say to loop through the list of data from Site A, how do you mean? I loop over Site A data in the following way (and therefore, not sure how to insert wordpress/php functions/statements in that):

    jQuery.ajax({
        url: urlr,
        method: "GET",
        dataType: 'json',
        success: function(data) {
            console.log(data);
            var html_to_append = '';
            jQuery.each(data.events, function(i, item) {
                s = item.start_date.substring(0, item.start_date.indexOf('T'));
                html_to_append +=
                    '<div class="col-md-2 mb-2 bg-light d-flex align-items-center justify-content-center"><div class="text-center pt-1"><h5>' +
                    s + '</h5></div></div>' +
                    '<div class="col-md-7 p-2 "><h3>' +
                    item.name + '</h3><p>' +
                    item.type + '</p><p>Fee: ' + item.entrylists[0].fees[0].amount + '</p></div><div class="col-md-3 d-flex align-items-center justify-content-center"><a class="btn btn-primary" href="' + item.enter_uri + '" role="button" target="_blank">Book Event</a></div>';
            });
            jQuery("#riderhq").html(html_to_append);
        },
        error: function() {
            console.log(data);
        }
    });

    Once again, thank you for your response.

    Have a lovely day!

    Thread Starter portia79

    (@portia79)

    Hi there,

    Thank you for your reply. I’ve cleared the cache, browsing data it’s stil the same. I don’t think it’s to do with my network or browser. Other people also reported the same. Also I don’t have any problems with wordpress dashboards on installation on another hosting.

    I just tried to do another installation. The same thing happens. It starts ok when you put the db credentials and then the next page throws the same error.

    Thread Starter portia79

    (@portia79)

    Thanks a lot.

    Forum: Fixing WordPress
    In reply to: create modules
    Thread Starter portia79

    (@portia79)

    Thank you.

    I have 2 questions.

    1. Thanks for the link. I have explored / read it. Could anyone answer my original question about the generic workflow in WordPress in terms of customising page areas?

    2. There is a section in the link provided above about creating your first template. Now, to my disappointment, as other tutorials on the internet, it only covers up to the point where you copy the content from page.php to yourcustomtemplate.php… and then you can do all the customisations you want. But really I’m after all those customisations I want. How do I start? I don’t seem to be seeing tutorials for that. I’m fine with HTML/CSS but I don’t believe I can just stick my html code there. For the argument’s sake, how would I create a custom template that would have say 3 columns?

    Thank you

    Forum: Fixing WordPress
    In reply to: Restore files
    Thread Starter portia79

    (@portia79)

    OK. Thanks. Will do it.

    Forum: Fixing WordPress
    In reply to: Restore files
    Thread Starter portia79

    (@portia79)

    Thanks – I’m not that concerned with customisations or themes as long as the content of the posts is retrieved. Can you just confirm so should I just take a note of the database credentials from the config file and delete all the folders from the installation directory. Then I should start with a fresh installation (from the hosting provider install scripts). Will there be an option to restore the content from a database?

Viewing 15 replies - 16 through 30 (of 44 total)