How to get a list of all posts and their categories?

If you want to export the data to a CSV or JSON file directly from the SQL query, you can use the MySQL INTO OUTFILE clause. SELECT wpd9_posts.post_title, GROUP_CONCAT(wpd9_terms.name) AS categories FROM wpd9_posts LEFT JOIN wpd9_term_relationships ON (wpd9_posts.ID = wpd9_term_relationships.object_id) LEFT JOIN wpd9_term_taxonomy ON (wpd9_term_relationships.term_taxonomy_id = wpd9_term_taxonomy.term_taxonomy_id) LEFT JOIN wpd9_terms ON (wpd9_term_taxonomy.term_id = wpd9_terms.term_id) WHERE … Read more

Fatal error: $post is null?

I’ve fixed the problem now. I got hold of my old database dump file from the old server. The reason the indexes weren’t added is because the sql contained rows like: CREATE ALGORITHM=UNDEFINED DEFINER=`tarikbil`@`localhost` SQL SECURITY DEFINER VIEW `wp_ …which was not getting executed due to insufficient user permissions. This meant the consequent indexing lines … Read more

Modify Post URL Programmatically

When you are using wp_insert_post() there is a param post_name. If you do not pass it then it will sanitise your post title and update. You only have control to add post_name but the full URL is created based on your Permalink settings.

Global $post value outside the loop

Yes, this is how it is supposed to work. The global $post variable is set quite early in the page load, at the wp hook. As you can see from the hook order, this is before the loop starts. Basically the $post object exists independent from its actual content in the database, which you retrieve … Read more

How to allow Contributors to edit their own posts, whilst still needing to be reviewed by an admin?

Steps for setting edited posts by contributors to “pending review”: 1. Adjust Contributor Capabilities Your modifications to the contributor role are appropriate for allowing them to edit their posts. Ensure they can edit posts but cannot publish them. 2. Automatically Revert Posts to “Pending Review” on Edit Add the following code to your functions.php. This … Read more

post loop with different design depending on post

Your $count++ needs to be after your endif statement. It’s not counting up because your counter is always at 0 which means you’re always in your “if” portion of your statement not your “else”. Like this: $args = array( ‘post_type’ => ‘post’, ‘post_per_page’ => 3, ); <?php $loop = new WP_Query($args); $count = 0; while … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)