Tag Info

Hot answers tagged

5

You can change it using following code, add it in your theme function.php or in plugin. remove_action ( 'wp_head' , 'rel_canonical' ) ; add_action ( 'wp_head' , 'my_rel_canonical' ) ; function my_rel_canonical () { ob_start () ; rel_canonical () ; $rel_content = ob_get_contents () ; ob_end_clean () ; echo str_replace ( "https:" , ...


4

Use a run-once script to clean it up. Just an outline, no code: Get all posts. See get_posts( array ( 'numberposts' => -1 ) ) For each post get all attachments. See get_children( array ( 'post_type' => 'attachment', 'numberposts' => -1 ) ) For each attachment get the attachment URL. See wp_get_attachment_url() If you find the attachment URL in the ...


3

This script will grab all of the attachments in the database, compare the file to one another through md5 and if it finds a duplicate and it has a 1 at the end of the file name it will remove the image: require('wp-load.php'); global $wpdb; $img_posts = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE post_type like 'attachment'"); ...


3

that could be caused by post revision being saved, and you should use wp_insert_post_data anytime you want to do something before the post is saved, here is an example plugin i just cooked up to test it and it looks like this: <?php /* Plugin Name: wpse37901 Plugin URI: http://en.bainternet.info Description: answer to ...


3

One way would be to keep track of which years you've already printed. Using your code: <?php $args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => ASC ); $attachments = get_posts( $args ); echo '<table ...


3

Any time you have a duplicate slug for a post or taxonomy, WordPress just adds '-2' to the end of the slug.


3

Theme template files are organized in this way because of the WordPress Template Hierarchy. Since all primary template files eventually fallback to index.php, it is certainly possible to use only the index.php primary template file. There are advantages and disadvantages to using either method. Generally speaking, the usefulness/efficiency of defining ...


3

Based on several different answers, with a SPECIAL thanks to EAMann's similar answer - here's the method I followed. Using new WP_Query instead of query_posts for this page. Defining the query variable ($main_query) as global. Querying a temp array ($temp_featured) with my featured posts. Creating an array with only the IDs of the `$temp_featured'. Note ...


3

Looking at your code you are calling the function ghoolo_mango() by using the the wp actoin hook. This is fine but be aware that it will add your post everytime a page loads. The problem is that you are also calling the function ghoolo_mango() within the function itself - i.e. it will keep calling it over and over. To fix the problem, remove the line ...


2

combining the two answer on this page, I found this worked. $args = new WP_Query(array( 'post_type' => 'post', 'posts_per_page' => -1 )); $loop = new WP_Query($args); while($loop->have_posts()) { the_post(); $args2 = array( 'order' => 'ASC', 'post_type' => 'attachment', 'post_parent' => $post->ID, ...


2

Just create your database table with a UNIQUE index (or indexes) to prevent duplicates, see MySQL: CREATE INDEX Syntax for starters. For the WordPress specifics take a look at Codex: Creating Tables with Plugins - Create Database Tables. Below example code is taken from there: global $wpdb; $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL ...


2

Try to use the following SQL query to fetch duplicate posts: SELECT p2.* FROM wp_posts AS p1 LEFT JOIN wp_posts AS p2 ON p1.post_content = p2.post_content AND p2.ID < p1.ID AND p1.post_type = p2.post_type AND p1.post_status = p2.post_status WHERE p1.post_type = 'post' AND p2.ID IS NOT NULL


2

Your two queries are identical, meaning you only need one of them. The basic solution is: global $testimonials; $testimonials = new WP_Query(array( 'posts_per_page' => 2, /* <-- get both */ 'post_type' => 'testimonial', 'post_status' => 'published', 'orderby' => 'rand', 'ignore_sticky_posts' => true /* you need ...


2

You can actually use a single index.php to create your WordPress theme. all you need is a style.css and index.php (along wit footer and header) it is all up to theme developer. I did that for old style classic bloc design a lot, but today, while designing complex CMS and Magazine themes; using different files according WordPress Template Hierarchy makes ...


2

I sometimes use this plugin http://wordpress.org/extend/plugins/duplicator/ it works pretty well if your server enviroment meets it's requirements. Otherwise, it's the good ole, mysql dump route that the other guys explained.


2

I don't believe it's covered by WP magic; and lately there's been much discussion of how bad it can be performance-wise to use %postname% alone, for example http://digwp.com/2011/06/dont-use-postname/ You might have better luck with %year%/%postname. Best of luck!


2

just add to your query SELECT DISTINCT $wpdb->posts. instead of SELECT $wpdb->posts.


1

you can use the same function simply hook it to the publish_page hook or any custom post type for that matter publish_{post type name} so just add : add_action('publish_page', 'clearDuplicatePosts');


1

Fetch all five posts in one query, store the result in a variable and take one each time you want to show an advertisement. Now you cannot get duplicates, and more important: you save four queries.


1

To answer the question directly, there is $wpdb->update but nothing that will strictly duplicate INSERT IGNORE that I know of. If $wpdb->update, does not work I am fairly sure that you will need to write your own query and use $wpdb->query and $wpdb->prepare.


1

Import the new table as wp_posts_2, then join them and delete all duplicates based on post_content; then merge the two tables. The following SQL query (untested!) should give the posts from the new table to be deleted: SELECT wp2.* FROM wp_posts_2 as wp2 LEFT JOIN wp_posts as wp ON wp2.post_content = wp.post_content WHERE wp2.post_content = wp.post_content ...


1

With the latest version of BackupBuddy you can actually do exactly that!


1

You need to do a foreach for the get_the_category Something like: while ($my_query->have_posts()) : $my_query->the_post(); $x = $my_query->current_post + 1; //you can use this to count instead $categories = get_the_category(); foreach($categories as $category) { if ($x == 1) ... //rest of your output // remember to us $category->cat_name; ...


1

There's plugin to do that - Duplicate Post While viewing a post as a logged in user, you can click on Copy to a new draft as a dropdown link under Edit Post in the admin bar. This will lead you to edit post page, change whatever you want and save. It'll save it as different post. - Quote for plugin Description


1

You can hook 'save_post' or 'wp_insert_post' (both executed the same in wp_insert_post()) to check for autosaves and notify the author(s) accordingly. The checks that I would do would be to check that the author of the autosave (aka, revision) and the new autosave are not the same, check that the post title is the same and that the content is SIMILAR, to do ...


1

Demilio, unfortunately the WordPress API seems to assume that custom fields do not have an 'empty' value, in the sense that update_post_meta and delete_post_meta, if given '' as the (previous) meta value perform the update/delete operation for all values for that key. This makes it difficult, for instance, if a custom field key has multiple values ...


1

Pass the post ID from the first query as a post__not_in parameter to exclude it from the second query. $nature_loop_1 = new WP_Query( array ( 'category_name' => 'nature', 'tax_query' => array ( array ( 'taxonomy' => 'highlight', 'field' => 'slug', 'terms' ...


1

As @helenhousandi said, why not use the WP_Query, try this: <?php // the args for the WP_Query // See more @http://codex.wordpress.org/Class_Reference/WP_Query $args = array( 'post_type' => 'matches', 'meta_value' => 'Shen', 'order' => 'DESC' ); ?> <?php $the_query = new WP_Query( $args ); ?> <?php if( ...


1

In the header loop, store the post id in e.g. $header_post_id In your sidebar: $testimonial_sidebar = new WP_Query(array( 'posts_per_page' => 1, 'post__not_in' => array($header_post_id), // exclude the post in header 'post_type' => 'testimonial', 'post_status' => 'published', 'orderby' => 'rand' )); if ...


1

Easiest way is to install Quick Page/Post Redirect Plugin. Then you'll just have to create a new page with the Title (and Permalink) country when editing this page you'll then have the possibility to redirect it to the other page.



Only top voted, non community-wiki answers of a minimum length are eligible