Piotr
Forum Replies Created
-
Forum: Networking WordPress
In reply to: Multisite, directories, domains and rewritesIt can’t be that easy. π Does it require subdomain install or would you try it on subdirectories? How should I set the path of a site? Now it’s ‘/wp/site1/’, so it should be… No, I’m lost.
Forum: Hacks
In reply to: Dynamically adding forms and optionsOh my, poor little cat. π
About those articles – the problem is that a single article on my site is composed of posts from one forum topic. Only the topic has a title in the database, there is no title for a single post. This is why I need to store the titles somewhere. There may be better ways, I hope I’ll find them, but for now I think this isn’t a bad solution. And it works.
Thank you for the tips. I hope that’s all I need to complete this.
Forum: Hacks
In reply to: Dynamically adding forms and optionsWell, this is surprising, I did something completely different from what you suggested and it works. π This was my inspiration. I made a form similar to the one in the tutorial. It creates an array which I’m saving in the options table using AJAX. JQuery lets me add new fields and a simple PHP loop inserts values of previously saved options, so I can edit or even delete them from the form. It’s exactly what I wanted. It appears that I have some problems with my JQuery – appended fields aren’t being validated for some reason – I’m sure it’s some newbie mistake that I made. I’ll find it sooner or later.
But I need one more advice on my articles section. As I stated before, I’m appending forum posts as article chapters. I could append them with ‘<!ββnextpageββ>’ so every chapter would be a separate page. This would be nice, but – no surprise here, I hope – I want something more. An index of those chapters, with titles., preferably on the sidebar. I have some ideas, but I need to know if I’m on the right track.
First thing, the pagination – on many sites it takes form of links ‘previous’ and ‘next’, but there are ways to make it look like ‘Page: [1] [2] [3] [4]’. If there are page numbers, there could be page titles, I just need a way to put them there. I’m thinking of two solutions. 1. putting the titles in my options table, maybe even using the form that I created or 2. putting the titles in a tag on my forum which after importing WordPress would see as a shortcode. In both cases I’m not sure how to use them later as links in the chapter list.
And the second thing is actually putting the list on the sidebar. Would it require creating a widget? And how to connect it to the post that is currently displayed?
I realize that those two problems may be easy to solve but until now I’ve been focusing on the backend functionality. I just need to know where to start and what to look for. So once again – I’m asking for a little help. π
Forum: Hacks
In reply to: Cannot insert termsI think I can help you. I did some inserting into the WordPress database and learned a few things. I didn’t use custom taxonomies but I thing it is close enough to what you’re doing.
First of all – you’re saying that nothing seems to be inserted. Well, you need to be sure. If the data is added to the database and you can’t see the results on your website then the problem is that you’re missing something. When I tried to insert some CPTs into WordPress and assign categories, the categories wouldn’t show on my site because I didn’t increment the term_taxonomy_id in wp_term_taxonomy table.
But if there is no data inserted, there may be a problem with your connection to the remote server. Check the password. π
Try to read this topic. It gets interesting around post 6 or 7. You may find that using wp_insert_term() isn’t very efficient.
Forum: Hacks
In reply to: Using one function for two scheduled events and a formUps, I forgot to mark the topic as resolved, I’m sorry. But I’ll share my progress while I’m here.
So… I did it. By using a form and some jQuery/AJAX I’m able to import and/or update specific news wih one click. It’s great. π And I’m amazed, how many possibilities I now have with the jQuery alone. Even the form validation is great this way. So thank you again for all the help.
But as I’m planning something bigger now, another section of my site, you’ll probably hear from me again in a couple of days. It’s going to be articles section with each article formed from a set of forum posts. I still need to wrap my head around it, but it looks like I’ll need to dynamically create a form and a set of options for each article that needs to be added. This is going to be complicated…
Forum: Hacks
In reply to: Using one function for two scheduled events and a formI think I understand. Or at least I get the idea – I’m not completely awake yet, so it’s too early to tell. π The most important thing is that I managed to use that variable and it works the way I needed, so… another small success. But thank you for taking the time to see what the problem was and explaining it to me. In moments like that I see how much I don’t know – it’s kind of scary. π Then again, two month ago I started with “chapter 1: what is PHP”.
Now I’m moving on to AJAX. To be honest, after reading articles you gave me I have no idea how to create what I need – I mean the form that passes my topic ID that I want to import. I think I understand how it works, but I need to learn about Javascript and Jquery. I’ll find some tutorials.
Forum: Hacks
In reply to: Using one function for two scheduled events and a formHmm, I did some reading – what if the server timeout value is lower than I need? I mean the set_time_limit() will work if execution time limit in php,ini is the only problem.
About the array – that’s exactly what I mean. More than that, when I try to pass an array ( key => value ), only the value is passed. I didn’t know what the problem was until I used print_r on the variable in my function. I know that I’m a newbie, but I think this isn’t normal. π
Forum: Hacks
In reply to: Using one function for two scheduled events and a formI still can’t tell you what the problem was, it looks like you can’t set up more events from a constructor. I have no idea why. So I used actions to call functions that set up those events and now both are there.
I also made a surprising discovery – the schedules don’t pass an array, only the value (at least when there’s one argument). Earlier when I used optional arguments, I think in add_settings_field function, the whole array was passed. Why is it different here?
And one final question, not really connected to this topic, but again, I just need some directions. While testing those schedules, I executed the import function with no limit. After importing about 90 posts it timed out. Not that I’m surprised, but I need to find a way around that. What are the best ways to deal with a long foreach loop?
Thanks for the help!
Forum: Hacks
In reply to: Using one function for two scheduled events and a formI was thinking about using two functions, but as you probably remember, importing posts in my case was quite complicated – inserting posts, terms, term taxonomies, modifying the data etc., is a lot of code. Using two such functions for almost the same thing didn’t seem very efficient. So I chose to pass an argument. I’m handling it this way:
if ( $arg[0] = 'limit' ) $limit = "LIMIT " . $options['limit']; else $limit = " LIMIT 2";(I’m using the ‘else’ for testing, I didn’t want to import all 900 posts just to see if this works. π )
And it does work, yay! π But there’s a problem. I’m trying to set a second event and for some reason I can’t do it. Here’s how I do it:
if ( ! wp_next_scheduled( 'hourly_import', array( 'limit' ) ) ) { wp_schedule_event( time(), 'two_min', 'hourly_import', array( 'limit' ) ); } add_action( 'hourly_import', array( 'News', 'news_import' ) ); if ( ! wp_next_scheduled( 'daily_import' ) ) { wp_schedule_event( time(), 'five_min', 'daily_import' ); } add_action( 'daily_import', array( 'News', 'news_import' ) );This in my class constructor. Obviously I’m using custom intervals to test these events, but only the first one is working. The daily_import event isn’t even added – I checked _get_cron_array, only the hourly_import event is set. What am I missing? Is there something I don’t know about adding multiple events or am I doing some, well… stupid mistake? There are no errors when I use the code.
As for AJAX, yes, you are right. There would be no sense in postponing it at this point. I just need to find out how to get the schedules up and running – I’ll need two or three more of these later on, as I’m planning to import some more data. And then I’ll move on to AJAX. Thanks for the links.
Forum: Hacks
In reply to: Using one function for two scheduled events and a formThanks for the reply. π I knew that sooner or later I will have to learn about AJAX. I Really hoped it would be later, but that won’t stop me. π Anyways, first I need to figure out how to use options in those scheduled events.
You were right about placing values in my query string, it was very simple, I managed to do it some time after I posted the question. My real problem is that I need two different queries for two different events. I may have not been to clear about this, so I’ll try again.
My daily event needs to fire the import function to insert/update all my posts, and my hourly event should fire the function to insert/update let’s say just 5 latest posts (this will be set by an option). So in case of the hourly event the query should have a limit, and in the daily event there should be no limit. How do I achieve this?
Forum: Hacks
In reply to: Looping posts with content from different databaseI’m back after some time. I hope you had great holidays.
I need to thank you for all your advice, bcworkz. After a while I’ve got to a point where I’m building an actual plugin and it works as intended. Now I’m trying to make it use the settings API to dynamically change the sql query and it’s getting a little too complicated for my level of PHP and WordPress knowledge, so it’s time to ask more questions. π But I think it will be better if I start a new topic. Thanks again!
Forum: Hacks
In reply to: Looping posts with content from different databaseIt works! Thank you bcworkz, I would have missed the taxonomies and it would cause quite a few problems.
One more question. Yeah, I know, no surprise here. π But this one is more interesting, I hope.
I’m thinking if there is a way to include author’s name in the inserted post. I can’t insert it – wp_post stores only authors ID while my forum table holds the user name. What may make it easier is that I don’t need it to be a link – so no profile or listing posts by the author. Is there an efficient way to include the name in the post outside of the inserting process that I’m doing?
Forum: Hacks
In reply to: Looping posts with content from different databaseThank you bcworkz!
You gave me an idea. A few even. I’ll start from the end. π
Scheduling the import won’t help me. I checked my server limits, it has daily queries limits. But the limit is in millions, and by doing simple math (if 10 posts require 200 queries, 1 post = 20 queries) I can see that inserting my 900 posts this way would give me about 18 000 queries. I know that’s A LOT, but even if I wouldn’t care and updated all my posts every hour, I still would be quite safe. I do care though, and the least efficient way I’m considering right now is doing the big update once a day and updating 10 latest posts every hour. That would give me ~23 000 queries. Still a lot, but could be worse. And I prefer to be efficient, so…
The direct approach. At the very beginning, when I did research on doing this import, I found out how to do this in MySQL – you can use good old INSERT INTO SELECT on both wp_posts and wp_term_relationships (I did it just five minutes ago to be sure if I remember correctly and it works). It’s a little complicated, but here’s how to do it.
First you insert data into wp_posts – you have to remember you’re not using wp_insert_post anymore, so you need to take care of most of the columns by yourself (post_title, post_content, post_name, post_date, post_date_gmt, post_type, post_status). In my case I needed to use FROM_UNIXTIME for both dates and LCASE and REPLACE space with “-” for topic_name.
Then the wp_term_relationships table – there are only three columns here (object_id, term_taxonomy_id, term_order). You insert your post ID in the first one, and in the term_taxonomy_id you insert the ID of your category or tag (which you’ll find in wp_terms table). The third column is set to 0 in my case, but it will probably change if I create categories inside categories, I’m not sure.
And that’s it. My WordPress doesn’t complain after this, I can see the post in the loop, in category view and single post view, so I think it’s OK. But you may be right about using the wp_set_object_terms. If I would need to set a category and a few tags, this could be better. I see a problem though.
wp_set_object_terms needs the post ID. If I’m not using wp_insert_post, I’m not getting the ID. Would it be OK to insert posts with my ID? Posts on my forum have a topic ID. It would be great if I could use it as post ID, later on I could even import topic replies as comments thanks to it. But will WordPress accept that? The ID is auto incremented, won’t there be any errors if I insert posts with IDs like 120 or 350?
Oh, and one more question – warning, it’s kind of noobish. ;p As I said, before I did this in MySQL (INSERT INTO wordpress.wp_posts (all the columns) SELECT all the values FROM forumdb.topics and a few joins), how do I use wpdb here? $wpdb for inserting columns, new wpdb ($mydb in my example) for getting post data from the forum but how should the whole query look like?
Thanks for your patience.
Forum: Hacks
In reply to: Looping posts with content from different databaseHi,
I’m back after a while. I’m not really stuck (yet), just looking for a few answers. I’m not sure if I should post another topic after setting this one as resolved… I’ll repost it if that’s necessary.
Anyways – after some reading I’ve created a custom post type, connected to my forum database and inserted a few posts into wp_posts. This required simple SQL functions to convert date and post name columns and surprisingly it works. But then I checked the number of queries and now I’m thinking it’s a terrible idea. Or I’m doing this terribly wrong. Here’s the code:
// $mydb is new wpdb connecting to forum database $forumrows = $mydb->get_results( $sql, ARRAY_N ); foreach ($forumrows as $row) { $news = array( "post_title" => $row["0"], "post_content" => $row["1"], "post_name" => $row["2"], "post_date" => $row["3"], "post_date_gmt" => $row["3"], "post_type" => "news", "post_status" => "publish" ); // checking forum section ID (column "4") to set category switch ($row["4"]) { case 62: $cat_ID = 2; break; case 63: $cat_ID = 3; break; } $post_ID = wp_insert_post( $news ); wp_set_object_terms($post_ID, $cat_ID,'category'); }As I said, it works – it queries post data from the forum, inserts it into wp_posts and adds a category depending on the forum section ID. But inserting just 10 posts resulted in 196 queries. If I were to insert all my posts, and there are about 900, I would probably use up database connections limit on my server. And still would need to update them regularly.
Is there a more efficient way? Or is my code that inefficient?
Any help will be appreciated.
Forum: Hacks
In reply to: Looping posts with content from different databaseThank you for your help. I still have some things to learn, but I’m on the right track, so I’ll mark it as resolved.