Dynamically setting permalink structure in Wordpress database creates 404 - php

It seems like others have experienced similar issues as me in the past on this subject, but nobody has provided a complete answer.
I'm attempting to run a PHP script to update the permalink structure in the wp_options table for a slew of Wordpress blogs. I want to connect to each database and update the permalinks without having to log in to each blog and update the setting through the UI.
I'm successful at connecting to the DB and updating the permalink_structure field with the proper codes, but it causes a 404 when attempting to view any posts.
Is Wordpress updating other tables/fields to fully enable the permalink?? I'm having a hard time finding the complete answer to this.
BTW: If there are edits being made to the .htaccess when this is done through the Wordpress UI, I'm not seeing it. The htaccess looks unchanged when I do this through the UI.
Thanks!

Wordpress permalink rewrite_rules are kinda troublesome. They are great if you wanna do basic stuff, but it's damn hard to do some complex rules with it.
What exact structure you wanna use?
Remember that htaccess created by Wordpress just redirects everything to index.php, which loads Wordpress system (wp_load()), and one of its components parses REQUEST_URI.
First it tries to to bind REQUEST_URI into one of its regexes, which makes it understand what kind of resource is being requested (category, tag, page, post, etc), then it tries to find which resource it is (if it's a post, find which post by it's slug).

Related

Wordpress Permalink Structure /post/post_id/anything-goes-here

I'm trying to setup a permalink structure like so 'example.com/post/post_id/any-text-here'. Which is kinda similar to how SO's permalinks to questions work. If the last part is changed it still loads the right page as long as the first part contains the correct question ID. I'm not sure if it's redirecting or pushing the question title back into the URL when you do that though.
I've tried /post/%post_id%/%postname%/, but that requires the correct post title in the url. I want that portion to not matter, but still have the flexibility in being able to place a title in it.
I'm guessing some server configuration changes may be required. I'm running NGINX.
Your proposed structure of /post/%post_id%/%postname%/ appears to work perfectly for me. http://domain.com/post/1/anything/ correctly redirects to http://domain.com/post/1/hello-world/, where hello world is the post title.
If this definitely is not happening for you, try disabling all plugins temporarily - something could be re-interpreting the url structure.

Integrating WordPress with a website, generically

So, I've read The Loop and I got the hang of it. (I created a page that lists the 3 most recent posts, a page that shows a page (as opposed to a post), and so on.)
However, it seems silly that, in order to integrate a WordPress blog into an existing site, I'd have to replicate all the different kinds of pages (lists of posts, the posts themselves, pages, etc.)
Is there a generic way of doing this?
The full idea is something like this.
The blog itself (with its ugly default template) is installed at http://blog.example.com.
I want to integrate the blog into an existing site, at the URL http://example.com/blog.
I'm doing a mod_rewrite that forwards the entire query string, e.g. http://blog.example.com/?p=7 gets rewritten to http://example.com/blog?p=7.
Now, in my PHP code at http://example.com/blog, I want to do something like this:
query_posts($_GET);
// display results
wp_reset_query();
That's where I'm stuck. Basically, I want to display exactly what's in the "content" area of a default WordPress template, on my site, according to whatever the query string dictates. Almost as if I were just using an iframe. I would rather not have to parse the query string to figure out whether I have to loop through this or that or turn off the $more global or not, etc.
What am I missing?
Instead, should I be installing the blog at http://example.com/blog and creating a template that mimics the website? This seemed complicated so I didn't go this route, but maybe someone should change my mind.
Appreciate any help, including advice for alternative designs.
Have you considered outputting the blog into a full rss/ outputting the blog as json and then pulling it in that way?

Drupal 6 - Site information broken after duplicating site. DB hacks needed?

I have a drupal site which I deved a few years ago. We duplicated it to a new site/domain/db (which pulls from a subdirectory of the original site)
I tried to only duplicate the site settings (views and content types), and leave out all the site node data (it is a content driven site, and we are launching a sister site). Everything wen OK. Unfortunately, in the new site, I find that I cannot update "site information" (which means I cannot set my front page). I tried to update the data in the DB, but that let to the relevant site settings field to appear blank
I i had to implement a ridiculous hack to deal with the fact that the front page is now technically a 404. Even more weirdly, the original site has the same problem now (all I can guess is that I updated the table from the wrong DB by mistake?!? ).
As best I can tell, this data is stored in "variable" in the DB. I have imported a good "variaable" table from an old copy of the site, but to no avail.
So I am completely stuck. If anybody has any leads whatsoever, I would be incredible grateful.
Thanks!

Replacing all outbound links to a certain domain in Wordpress

I maintain a Wordpress site for a client of mine. They do all the content, I just keep it running and do the theme work.
A site they've linked to a few hundred times has changed domain and they've (very rudely) not redirected traffic from their old domain, so users clicking on an old link see a 404.
So we're left in the position where we need to fix all the links. The static ones (in theme files) have been easy enough to replace but, as I say, there are hundreds of these blighters littered all over the website in the posts.
Is there a quick method to find-and-replace links like this?
If there's not a Wordpress or PHP method, I'm happy to log in to the database over SSH and fire some SQL off manually... But what SQL do I want?
Running a query is indeed the easiest and cleanest way.
Back up the database of course
According to this blog post (I'm too lazy to look the columns up on a live WP but this looks about right), the right query is
UPDATE wp_posts SET post_content =
REPLACE (post_content,
'http://www.oldsiteurl.com',
'http://www.newsiteurl.com');
There also is a WordPress plugin for that: http://wordpress.org/extend/plugins/search-and-replace/ I have used it when moving my own site and it worked nicely.

Wordpress: using a test theme only for a specific user

I'm testing a new template for a wordpress based site, and I'd like to test it directly on the live version instead of making copies. I thought I could create a test user (wordpress is bridged with vbulletin which handles user auth), serve the usual theme to anyone BUT that specific user, who would get the new testing one.
I don't want to install a plugin, I'm looking for the right place to edit to insert this check:
if logged user == test_user_id
serve 'testtheme'
else
serve 'normaltheme'
The userid can be get from $_COOKIE.
I tried hacking the get_template() function in wp-include/theme.php but apparently that was not enough. Any suggestion?
This is the best way to "test" or develop a theme behind the scenes without needing to alter too much of your Wordpress core or make custom changes...
http://digwp.com/2009/12/develop-themes-behind-the-scenes/
Just logging into my old Wordpress.com blog, I see that I can do all the previewing I want from the themes manager already - click around to any page I like, or bring up the frame's URL to see what query string I'd have to append to a URL to get the same preview, e.g.
?preview=1&template=pub/mytheme&stylesheet=pub/mytheme
Any reason that's not enough?
Perhaps you should add a column to your user table, call it "is_beta" and if it's set to 1 then enable beta features/themes. This way you can easily add or remove people from the beta, and when you're beta is ready to launch, you flush the column for everybody and make the features default.

Categories