Alter SQL query to return posts with unique custom field value, no duplicate values

I currently have a list of posts with the custom field "Name," with several posts having the same value for "Name." I would like to retrieve a list of posts that all have unique values for "Name." For example, Post 1 and Post 2 can't both be "Michael." Is there a way to do this by altering the SQL query directly, before it's executed? I am currently using the function below (limit 5 posts and ordered randomly) to alter the query.               function alter_the_query( $request ) {             $dummy_query = new WP_Query();  // the query isn't run if we don't pass any query vars             $dummy_query->parse_query( $request );                  if ($dummy_query->is_category()) {             $request['posts_per_page'] = 5;                     $request['orderby'] = 'rand';             }             return $request;     }      I am trying to avoid using SQL directly for sake of compatibility with future versions of Wordpress, but if that's the only way then I'm still open to those suggestions.


Sub Domain's Pages return 404

Need some help, I created these websites               http://mccsedu.org     http://parents.mccsedu.org     http://faculty.mccsedu.org     http://students.mccsedu.org      The main site is working fine, but the pages of the those subdomains are not working. it always returns 404, you can try visiting those sites and click on any posts or pages..


Handling large N data in WordPress

I realize that this also pertains to PHP and MySQL in general, but the context and operation is within WordPress. ## Introduction I am currently developing a plugin that creates and saves data about exercises: It essentially lets me create workouts (select exercises and details about them), which are stored either as meta-data for regular posts or as drafts within a custom post type, and also create data about how the workout turned out (completion/details). The data is enumerated from the form into something like this (example set of data from a single workout):               Array     (         [compound_exercises-incline_and_standing_shrugs-sets] => 8         [compound_exercises-incline_and_standing_shrugs-reps] => 2         [compound_exercises-stiff-legged_deadlift-sets] => 8         [compound_exercises-stiff-legged_deadlift-reps] => 1     )     Array     (         [compound_exercises-incline_and_standing_shrugs-sets] => on         [compound_exercises-incline_and_standing_shrugs-sets-sets] => 8         [compound_exercises-incline_and_standing_shrugs-sets-reps] => 8         [compound_exercises-incline_and_standing_shrugs-sets-weight] => 16         [compound_exercises-incline_and_standing_shrugs-sets-completed] => 1         [compound_exercises-incline_and_standing_shrugs-sets-result] => 1         [compound_exercises-incline_and_standing_shrugs-sets-info] => Lorem ipsum dolor sit amet...         [compound_exercises-incline_and_standing_shrugs-reps] => on         [compound_exercises-incline_and_standing_shrugs-reps-sets] => 5         [compound_exercises-incline_and_standing_shrugs-reps-reps] => 10         [compound_exercises-incline_and_standing_shrugs-reps-weight] => 69         [compound_exercises-incline_and_standing_shrugs-reps-completed] => 1         [compound_exercises-incline_and_standing_shrugs-reps-result] => 4         [compound_exercises-incline_and_standing_shrugs-reps-info] => Lorem ipsum dolor sit amet...         [compound_exercises-stiff-legged_deadlift-sets] => on         [compound_exercises-stiff-legged_deadlift-sets-sets] => 3         [compound_exercises-stiff-legged_deadlift-sets-reps] => 8         [compound_exercises-stiff-legged_deadlift-sets-weight] => 17         [compound_exercises-stiff-legged_deadlift-sets-completed] => 1         [compound_exercises-stiff-legged_deadlift-sets-result] => 1         [compound_exercises-stiff-legged_deadlift-sets-info] => Lorem ipsum dolor sit amet...         [compound_exercises-stiff-legged_deadlift-reps] => on         [compound_exercises-stiff-legged_deadlift-reps-sets] => 3         [compound_exercises-stiff-legged_deadlift-reps-reps] => 16         [compound_exercises-stiff-legged_deadlift-reps-weight] => 100         [compound_exercises-stiff-legged_deadlift-reps-completed] => 1         [compound_exercises-stiff-legged_deadlift-reps-result] => 3         [compound_exercises-stiff-legged_deadlift-reps-info] => Lorem ipsum dolor sit amet...         [general-data-weight] => 60         [general-data-chest] => 10         [general-data-waist] => 10         [general-data-thighs] => 10         [general-data-calves] => 10         [general-data-arms] => 10         [general-data-forearms] => 10     )      The first array contains the workout, and planned amount of sets and repetitions; and the second the second details about how the workout went. The first thing to notice here is that just one workout could be several KBs in size. It would not be uncommon, for example for a few years amount of workouts, to reach several MBs in size when aggregated. Also, I am aware of software that solves these tasks easily independently of WordPress, but I am trying to integrate this solution into WordPress because it famously can handle large amounts of data and easily integrate with blogging and other solutions. ## Problems Though caching partial-data from several MBs of MySQL results is not necessarily hard, the problem is in retrieving it and handling it incrementally and asynchronously: I need WordPress to update a set of transients by appending data without disturbing user-interaction. This would entail handling some preset amount of data to create a ready-to-display (for example as a table or a graph) set of this data. My main concern is the load to the WordPress database and potentially to the server its hosted on, and so I want to make sure the data retrieval and handling is as optimal as possible both when creating, saving and displaying the data. ## Questions   1. What would impact the database load least: Storing data as posts with post meta in the custom post type, as ambiguous post meta, as hierarchical taxonomies with metadata (by plugin, ref: q49333), as data in a custom database table, or some alternative option?   2. Are cronjobs, direct-action or ajax better for appending newly added data to a transient containing previous data (for example a months worth)?   3. Assuming that the aforementioned workout and results array are necessary, which would save more space, serializing (as WordPress does by default), json encoding, or another alternative?   4. Upon retrieving a large amount (for example a months worth) of data, what method would be less system intensive for aggregating it? Assuming it has to be systematized into comparable units, can this be done client-side to lessen the load, or would a pre-generated transient (with ready-to-display data) be better?   5. In terms of exporting/importing data, what pre-existing system would best handle this amount of data? IE., does WordPress have a built-in CSV export/import? I am assuming that the regular Import/Export tool won't handle a large data load.


Wordpress Shortcodes - Optional Styles

i'm creating some custom shortcodes for my wordpress theme. Shortcodes are by nature optional on pages/posts, but may contain css, js or other files. My question is, how can i enqueue css styles ONLY IF a particular shortcode has been used ? I would not want to load everything for no reason.


Conditional widget_form_callback

I have attempted to develop a way to set something in a widget only if the widget exists in a specific sidebar. The code below looks for sidebar called 'footer' and shows the select option above the default options in the widget. However, it doesn't appear when I drag a new widget into the sidebar. When I press save, the option then appears where I will have to then select the option and hit save again. What am I missing to ensure it loads as soon as it's dragged into the sidebar?               function mytheme_colspan_widget_extend( $instance, $widget ) {         if ( !isset($instance['colspan']) )         $instance['colspan'] = 3; // set a default if none is set         foreach ( wp_get_sidebars_widgets() as $sidebar => $widgets ) {            if ('footer' == $sidebar && in_array( $widget->id, $widgets )) {             echo "
\n";             echo "\tid_base}-{$widget->number}-colspan'>Column Span: \n";             ?>             <select name="widget-<?php echo $widget->id_base.'['.$widget->number.'][colspan]'; ?>" id="widget-<?php echo $widget->id_base.'-'.$widget->number; ?>-colspan">             <option>Select:</option>             <option<?php if ($instance['colspan']=='1') {echo ' selected';} ?> value="1">1</option>             <option<?php if ($instance['colspan']=='2') {echo ' selected';} ?> value="2">2</option>             <option<?php if ($instance['colspan']=='3') {echo ' selected';} ?> value="3">3</option>             <option<?php if ($instance['colspan']=='4') {echo ' selected';} ?> value="4">4</option>             <option<?php if ($instance['colspan']=='5') {echo ' selected';} ?> value="5">5</option>             <option<?php if ($instance['colspan']=='6') {echo ' selected';} ?> value="6">6</option>             <option<?php if ($instance['colspan']=='7') {echo ' selected';} ?> value="7">7</option>             <option<?php if ($instance['colspan']=='8') {echo ' selected';} ?> value="8">8</option>             <option<?php if ($instance['colspan']=='9') {echo ' selected';} ?> value="9">9</option>             <option<?php if ($instance['colspan']=='10') {echo ' selected';} ?> value="10">10</option>             <option<?php if ($instance['colspan']=='11') {echo ' selected';} ?> value="11">11</option>             <option<?php if ($instance['colspan']=='12') {echo ' selected';} ?> value="12">12</option>             </select>             <?php             echo "
\n";            }         }         return $instance;     }     add_filter('widget_form_callback', 'mytheme_colspan_widget_extend', 10, 2);               function mytheme_colspan_widget_update( $instance, $new_instance ) {         $instance['colspan'] = $new_instance['colspan'];         return $instance;     }     add_filter( 'widget_update_callback', 'mytheme_colspan_widget_update', 10, 2 );


Audio and video shortcodes not working properly

I'm having some trouble with Wordpress's built-in shortcodes for audio and video. When I embed a video, it basically gives me a black box and has a link to download the file at the top; when I embed audio, it adds it, but there is no play button. I can still click where the play button is and it will play, but no actual button. I tried using different plugins, mediaelement.js and widgetkit (by yoothemes) among others, but everything is giving me the same type of output. What am I doing wrong? I would really really appreciate any help I can get. Additional Info:   * using Thesis Theme 2.1    * have tried disabling all plugins to see if anything was conflicting; made no difference    * have tried removing all jquery scripts from the head; also made no difference   * all css and js files appear to be linked properly (all styles and jquery animation are in place)   * here's a test page of my site so you can see what's displaying: http://kitabummuneer.com/newsite/index.php/test-page/


is_archive() returns false on the archives page

I've followed the official documentation to create my archives page: http://codex.wordpress.org/Creating_an_Archive_Index It works fine exept that "is_archive() returns false when I'm viewing this page. Any idea ?


PhotoPress Gallery plugin cannot retrieve my photos after overriding the gallery output

I am using PhotoPress Gallery plugin and PhotoPress taxonomy by padams to create a gallery using terms and keywords on my Stock Photo site. It's working well until I decide to override the Gallery output of wordpress for additional functions and stylings. Now, it doesn't retrieve the photos and I need to actually attach them on the page. But this is kind of troublesome because I would keep on adding photos on this pages like a normal stock photography site would do that is why I use the PhotoPress Gallery plugin together with the PhotoPress Taxonomy for easier uploads. The output code that I use comes from this site I think it has something to do with the extract code:               extract(shortcode_atts(array(         'orderby' => 'menu_order ASC, ID ASC',         'include' => '',         'id' => $post->ID,         'itemtag' => 'dl',         'icontag' => 'dt',         'captiontag' => 'dd',         'columns' => 3,         'size' => 'medium',         'link' => 'file'     ), $atts));      and the query:               $args = array(         'post_type' => 'attachment',         'post_status' => 'inherit',         'post_mime_type' => 'image',         'orderby' => $orderby     );      What could I change in this query to make it the photos appear? Here's a sample shortcode that works before overriding the gallery `[gallery taxonomy="photos_collection" term="stock-photo" columns="6" size="thumbnail" itemtag="li" icontag="th"]`


How can i add validation to this login form with out it redirecting to the wp-login.php page

Im using the code as posted on the website below, to create a hard coded login form. http://www.wprecipes.com/add-a-login-form-on-your-wordpress-theme What would be the best way of incorperating some validation with this or using the default wordpress error messages? the whole point in hard coding the form is that the user isnt taken away from the content to the default wp-login.php page throughout the login process. Regards, Tom Kiddle


how to put a custom field value in variable

function zh_get_invoice_round_off_number()          {             global $post;             return get_post_meta($post->ID, 'invoice_round_off_number', true);         }              function zh_invoice_round_off_number()          {             echo zh_get_invoice_round_off_number();         }


Where to save common libraries?

I have a multiple-site WordPress install. I have decided to centralize as many of my libraries as possible into one spot, for obvious organizational reasons, and in order to reduce bloating. Many of those libraries can be used both in plugins and themes. My first idea is to create a ' ** _myLibs_** ' (or other name) directory inside **_wp-content_** where I would save all those libraries. Anybody has a better idea? Would there be any reasons NOT to do this?


How can I show the Jetpack Subscriptions form in a page?

In the Jetpack plugin, the subscriptions module can be included in your blog by following these instructions: > To use the Subscriptions widget, go to Appearance → Widgets. Drag the widget > labeled “Blog Subscriptions (Jetpack)” into one of your sidebars and > configure away. I am interested in including the subscriptions form on a Page within my site, in the main section of the page. Is there some sort of shortcode or other way that I can easily include the subscriptions form within my page content? Or to do this, would I need to define a new sidebar, put the subscriptions widget in the sidebar, and them make a custom template that includes this new sidebar within this page (quite a cumbersome exercise)?


How to display all the categories a post is in

How do I display all of the categories that a post is in, in sentence format. eg. cars, boats, aircraft, bicycles.


Wordpress comment pagination : newest comments on first page

I use Wordpress commment pagination as follows:   * paginated comments   * comments displayed with the newest comments at the top of each page   * 50 comments on each page   * first page displayed by default The problem is that I am trying to achieve YouTube like comments such as - newest comments on first page, first page being displayed by default, then older comments in order on page 2, 3 etc The problem is that Wordpress comments are structured in such way,that I cannot achieve this by changing the "Discussion" settings. I have tried different options, such as extending the Walker's paged_walk() function, or to reverse the comments, or even pulling the comments with a MySQL query and using paginate_link() - but can't seem to be able to achieve this type of comments hierarchy. Any advice is appreciated, thank you! **Solution:** I have found a solution as follows:   * into functions.php I have inserted a custom function that sorts the comments by date (newest comments first) by using an associative array sorting as can be seen here   * into the Wordpress settings I changed the following at Settings -> Discussion _Comments should be displayed with the comments at the top of each page_ So now my comments are being displayed newest first (at top) with page numbering starting from 1. The only issue that I see, is that when posting a comment the user is redirected for some reason to the last page of comments.


Javascript Helpers

Are there any WordPress specific Javascript functions that could be used as helpers when writing custom code? I am thinking specifically of one that would pull back the base URL of your install, but any helper functions built into WordPress would be nice to know.


Give Friend Post Management

On my site you can create a post for someone who is your friend in site. How do I give permission to my friend to also manage that post as well as me?


insert an html tag using php plugin

I wanted to create a new `<div>` on top of the `<div id="wpwrap">` in **adminheader.php** and a closing tag below the `</body>` on **adminfooter.php** should i just go create a new div manually? or use a plugin to insert those html tags. thanks.


Limitless amount of posts in custom archive page

I want to get rid of pagination completely on my custom archive, I want everything on 1 page. How can I do this? Currently I'm getting my posts with:               <?php query_posts($query_string . '&orderby=title&order=ASC'); ?>     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>      The codex pages on query_posts and pagination don't seem much help, they're just telling me how to limit it but not saying how I can get rid of the limit. I've used the bones starter theme so I don't know if that affects the default behaviour.


How to add content at the end of posts?

I am trying to add custom fields at the end of posts. I succeeded showing the custom content using the below mentioned code. But the main post's content was replaced. :               function custom_content_filter_the_content( ) {        the_field("field1");     }     add_filter( 'the_content', 'custom_content_filter_the_content' );      So I want to try this as in below mentioned example:               function custom_content_filter_the_content( $content ) {         $custom_content = 'some_content_appears_here';         $custom_content .= $content;         return $custom_content;     }     add_filter( 'the_content', 'custom_content_filter_the_content' );      Want to replace `'some_content_appears_here'` with `<span class="custom_fds"><?php if( function_exists('the_field') ) the_field('field1'); ?></span>`. Could any tell me how to use the `<?php the_field() ?>` with in functions.php to add custom fields(created with Advanced custom fields) at the end of the post content(that is easy when we use in templates but not in funcitons.php) ? **Update** : @G.M 's code helps me to achieve what I want. Here is the final code:               function custom_content_filter_the_content( $content ) {         if ( function_exists('get_field') ) {           $content .= '' . get_field('field1') . '';           $content .= '' . get_field('field2') . '';                   }         return $content;     }     add_filter( 'the_content', 'custom_content_filter_the_content' );      Thanks to @G.M. I have a few questions related to the custom content.   * I am displaying multiple fields in the single function. Is that ok?   * Instead of the end or beginning of the post, is there a way to choose a position for custom content any place with in `the_content` ? For example, if I use any plugins for social sharing, they display the content at the same place, I want to change positions of these two types of custom content.


Inconsistent title for posts

I remember, I had edited some part of my theme for optimizing the title values. Currently in google I see this. Whereas when I open a post, the site name is not appended to the post title. I looked at the `header.php` of my theme and found the following line:               <title><?php seotitles(); ?></title>      I am using "All in one SEO" plugin and have set the title and description of each post manually and when I do so, I don't append the site name in the post name. How can I bring what I see in google and what the user sees in sync with each other?


Display the current post author and his url in the post header

I'm making some changes in my theme. I want that when they visit a Post the header should contain the post author and his URL. right now I'm using this:               echo ''.get_userdata($posts[0]->post_author)->data->display_name.';      the auhtor's display name is working correctly, but the link is going like               www.mysite.com/?auhtor=0      instead of this (for example)               www.mysite.com/?auhtor=36      so this is the code in the header               Display name      instead of this:               Display name      by the way: I'm doing this outside a loop.


wp_get_object_terms(): count relative to passed IDs?

I know when you `wp_get_object_terms()` you get a "count" member variable for each term object returned, but that "count" is what's in the `$wpdb->term_taxonomy` table in the database, it's not relative to the IDs you pass in as the first parameter. How do I get that number, though? Example, something like:               $query = new WP_Query(array('post_type' => 'foo', 'numberposts' => 20));     $ids = wp_list_pluck($query->posts, 'ID');     $terms = wp_get_object_terms($ids, 'multi_post_type_tax');      So I want the count returned to be relevant to the query, meaning the count I get is only for the passed in post IDs. Each term object returned from the tax "multi_post_type_tax" may have a count of 400 because it applies to other post types that aren't in my query, but since I passed in specific IDs, I want that count to apply to that query, meaning a count > 20 wouldn't make any sense at all (and most likely for a particular term, it'd be less than 20, I can't see every post in a post type having the same term usually). It seems like that would work but the returned value from `wp_get_object_terms` has unique objects.


Defined function gives undefined function error.. is a custom function

OK so I'm making a theme here at work and I'm sectioning off all functions that aren't add_action or the like. I'm using them through-out for different things. They are stored in a file called 'theme_functions.php' So far I have like 7 functions in there, they're all running perfectly fine. I added another and when I try to use in anywhere, it gives me `Fatal error: Call to undefined function myFunction() in /Users/mycomputer/PHP/MY_SITE/wp-content/themes/MY_THEME/page-home.php on line 15` I asked PHP if the filed existed and it tells me YES `echo file_exists(plugin_dir_path(__FILE__)."_include/inc/theme_functions.php") ? "YES" : "NO";` I am including like so: `require_once plugin_dir_path(__FILE__)."_include/inc/theme_functions.php";` I know it's not scope because other functions work. My code is clean and I made sure my syntax was on point... So I'm resorting to asking here because I have absolutely NO clue what is going on. CODE:               function myFunction($termName, $postsPerPage=10){       $category = get_term_by( 'name', $termName, 'category' )->term_id;       $posts = array();            $post_args = array(         'posts_per_page' => $postsPerPage,         'category' => $category,         'orderby' => 'post_date',         'order' => 'DESC' );       $p = get_posts($post_args);            foreach ($p as $i => $post) {         $img = get_primary_image($post->ID, '300'); // this is another non-wp function within the same file that WORKS         $title = $post->post_title;         $link = get_permalink($post->ID);              $excerpt = substr($post->post_excerpt, 0, 90)."...";         $x = array(           'img' => $img,           'title' => $title,           'excerpt' => $excerpt,           'link' => $link         );         array_push($posts, $x);       }       return array_chunk($posts, 2);     }      If anyone can point me in the right direction, I will love you forever and ever (restrictions may apply).


Change link to other post to shortlink in the editor

Curently if we use the insert link dialog to insert a link to another post, WordPress always use the permalink of that post. The problem is when we change permalink structure, that link will be broken. I'd like to ask if there is a way to change the link from permalink to shortlink like `?p=123` to make it work in any circumstance. Thanks.


How to modify/ customise NextGen Gallery's templates?

I would like to customise the "Image browser" template in particular. I'm trying to make clicking on an image redirects to the next image in a gallery, just like how Facebook image browser works.   (This is not a cosmetic change with CSS - CSS change is not what I mean by customising the tempaltes) I can always edit `/wp-content/plugins/nextgen-gallery/view/imagebrowser.php` but it's a hack and it's not upgradable when next version of NextGen Gallery is out. Is there anyway I can overwrite the template imagebrowser.php in my theme?


Prevent plugin from deleting important directories

I want to allow users to upload custom files to specific plugin directory. The problem is, obviously, that WP removes everything upon plugin version update. I think that the `upgrader_pre_install` and `upgrader_post_install` hooks may be useful, but unfortunately so far I wasn't able to find any info to help me. In your opinion, can these hooks be used to retain a directory and if so, how? Should I simply copy the directory elsewhere, like the uploads folder, and copy it back with `upgrader_post_install`? What would be the best practice? Thanks


Why have <?php and ?> on every line

I've seen this convention pretty much everywhere, and, at times, it comes close to driving me nuts:               <?php //The loop ?>     <?php while ( have_posts() ) : the_post(); ?>         <?php the_content(); ?>     <?php endwhile; // end of the loop. ?>      Where the `<?php` and closing `?>` are on every single line, even if there is no intervening HTML code. **My question is: Why?** Why include all these extra tags? To me, it seems this convention adds a significant amount of clutter to code, is annoying to follow in the first place, and adds that many more places to accidentally leave out an opening or closing tag. **NOTE** This is code pulled from the Twenty-Twelve theme, the example given by WordPress.


Move posts to top of WP_Query if in certain Taxonomy?

I'm trying to figure out the best way to promote certain (custom) posts to the top of my Wordpress loop. I can't use sticky posts because they are all in a custom post type.. I was thinking of using a taxonomy to do this, however I'm not sure if it will work, I am thinking I may need 2 loops?


Custom Query based on custom field of a single post

I have posts which have a custom field date in the format yyyy-mm-dd. What Im trying to do is list all the posts for a specific year on the side of a single page based on the year in the custom field of this post and separated into months. So for example if the post has a custom field date of 1990 then I want to list all posts from 1990 on the side of the page and sorted into months. I have to use this custom field date and cannot use the Wordpress internal date function. Below I extracted just the year from the custom field date for the query and it returns all the links to the posts from the year the single post custom field is dated. This query appears on the side of the single post page template outside of the single post loop. Im trying to figure out how I can now sort these posts into months? So January followed by all the post links for this month, February and so on...               <?php      $histyear = substr (get_post_meta($post->ID, "historic-date", true),0,4);      $querystr = "     SELECT $wpdb->posts.*      FROM $wpdb->posts, $wpdb->postmeta     WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id      AND $wpdb->postmeta.meta_key = 'historic-date'      AND $wpdb->postmeta.meta_value = $histyear      AND $wpdb->posts.post_status = 'publish'      AND $wpdb->posts.post_type = 'post'     ORDER BY $wpdb->postmeta.meta_key = 'historic-date' DESC      ";           $pageposts = $wpdb->get_results($querystr, OBJECT);           ?>           <?php if ($pageposts): ?>      <?php global $post; ?>      <?php foreach ($pageposts as $post): ?>      <?php setup_postdata($post); ?>           <div class="post" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">      <?php the_title(); ?>

      <?php endforeach; ?>      <?php else : ?>


Stop `update_post_meta` from working each time page refreshes?

So my code I have here including `update_post_meta` makes it work when clicking a button I have although what I fail to find out is how I can prevent `update_post_meta` from working on each page refresh/visit because I have this button on a certain page. This is the code:                   <form action="" method="post">             <input type="submit" value="Test" id="submit">             <?php             $post = array(                 'post_title'   => $column1,                 'post_status'  => 'draft',                 'post_type'    => 'bedrijf'             );                  $thisid = wp_insert_post ( $post, true);             if(!isset($_POST['submit'])){                 if ( is_wp_error($thisid) ) {                     return get_error_codes();                 }             }else{                 wp_insert_post($thisid);                 update_post_meta( $thisid, 'field_1223ewedwd3123', $column2);                  }             ?>               </form>


SQL query to get posts from multiple categories but not in a category

I need to get the last posts' ID and the post_tile within categories 1 and 2, and exclude those within category 3. It must be SQL, because if I use WP_Query it retrieves too much info and I only need the ID and post_title. The following query works fine getting posts from the 2 categories, but if I try excluding the third one, it doesn't work:               select distinct p.ID, p.post_title                 from wp_posts p,                  wp_terms t, wp_term_taxonomy tt, wp_term_relationships tr,                 wp_terms t2, wp_term_taxonomy tt2, wp_term_relationships tr2                      where p.id = tr.object_id                 and t.term_id = tt.term_id                 and tr.term_taxonomy_id = tt.term_taxonomy_id                      and p.id = tr2.object_id                 and t2.term_id = tt2.term_id                 and tr2.term_taxonomy_id = tt2.term_taxonomy_id                      and (tt.taxonomy = 'category' and tt.term_id = t.term_id and t.term_id = 15)                 and (tt2.taxonomy = 'category' and tt2.term_id = t2.term_id and t2.term_id = 5)                 ORDER BY p.ID DESC                 LIMIT 0, 60      Any help? Thanks in advance :)


Pretty URLs and custom post types

I've read the posts on WP SA on rewrites and custom post types, but I can't figure out why my search for 2 different post types isn't working. I'd like my URLS to become `example.com/search/events/searchtem` and `example.com/search/artists/searchterm`. I have a CPT called 'events' and one called 'artists'. My custom permalink structure is set to `/%postname%/`. My search forms:               <form class="search-form" action="<?php echo home_url('/events/'); ?>" method="get">     <input id="s" name="s" type="text" class="span4" />     <input class="search-button" type="submit" value="Zoek" tabindex="-1" />     </form>          <form class="search-form" action="<?php echo home_url('/artists/'); ?>" method="get">     <input id="s" name="s" type="text" class="span4" />     <input class="search-button" type="submit" value="Zoek" tabindex="-1" />     </form>      If I search, the URLs become `example.com/events/?s=searchterm` and `example.com/artists/?s=searchterm` but the return a 404. This is weird, because putting `?s=` behind any URL turns it into a query right? These are the results with the nice-search functions (see below) disabled or enabled (no difference). If I change `<?php echo home_url('/events/'); ?>` to `<?php echo home_url('/'); ?>` and add `<input type="hidden" name="post_type" value="events" />` with nice-search (see below) disabled everything works as expected (URL becomes `example.com/?post_type=events&s=searchterm`). With nice-search enabled, the results become example.com/search/searchterm (so it does rewrite) and it does take me to my search results page but it searches everything instead of just one post type. The functions from nice-search (I'm using the roots theme) which consists of two parts:               function roots_nice_search_redirect() {       global $wp_rewrite;       if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) {         return;       }            $search_base = $wp_rewrite->search_base;       if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) {         wp_redirect(home_url("/{$search_base}/" . urlencode(get_query_var('s'))));         exit();       }     }      if (current_theme_supports('nice-search')) {       add_action('template_redirect', 'roots_nice_search_redirect');     }      and               function roots_request_filter($query_vars) {       if (isset($_GET['s']) && empty($_GET['s'])) {         $query_vars['s'] = ' ';       }            return $query_vars;     }      add_filter('request', 'roots_request_filter');      After reading the posts, I think I need to alter my rewrite function but I don't really know how to... Also, I'd like to use `<?php echo home_url('/events/'); ?>` instead of `<input type="hidden" name="post_type" value="events" />` if possible and I don't use pagination.


how to move <img> from content and place them elsewhere on a page template?

An existing website have many images placed within the content of pages. I'd like to redesign the template, separating the display of text and images. How could i do that?


BBPress Search results in Wordpress search

I want to display in Wordpress search results page - 10 or less found results from BBPress (plugin) forums. I know that BBPress use custom post types (forum, topic, reply) but I don't know how to do it. I try with WP Query, but it didn't show nothing. I don't want to override BBPress search page and functions, I just want to show some results in Wordpress search page. Is this possible? Thank you all in advance. Here is the query I try:               <?php          // The Query         $the_query = new WP_Query( array (             'post_type' => array('topic', 'reply'),             'posts_per_page' => 10,             's'=> $s         ));              // The Loop         if ( $the_query->have_posts() ) {             while ( $the_query->have_posts() ) { $the_query->the_post();                 echo '<li>' . get_the_title() . '</li>';             }         } else {         // no posts found         }         /* Restore original Post Data */         wp_reset_postdata();     ?>


How to change blog category, author URL in wordpress

I have create a WordPress page with slug blog. I can easily access the blog par with `/blog`. Now what I want is to add `blog/` in front of all the urls in my blog, like `blog/category/first`, blog/author/pramod.. I have try this by changing category base and author base but it gives me page not found error. Please let me know is there any other way to do this. Asked same question on SO but no reply


How show post only from after custom date

I have custom post type. In this custom post type I have custom field with date in format: 23/09/2012 How to show only posts, which currently date is before date from these custom field? Sory for my english. Tom


wp_enqueue_script : how to change loading order of scripts?

I would like to know how to list all scripts loaded on a page, ranked by order and change this order.


How to make wp-login.php not accessible

I've successfully made wp-admin not accessible (redirected to 404 page) here is the codes in my function file:               add_filter('site_url', 'wpadmin_filter', 10, 3);          function wpadmin_filter( $url, $path, $orig_scheme ) {         $old = array( "/(wp-admin)/");         $admin_dir = WP_ADMIN_DIR;         $new = array($admin_dir);         return preg_replace( $old, $new, $url, 1);     }               function redirect_wp_admin(){         $redirect_to = $_SERVER['REQUEST_URI'];         if(count($_REQUEST)> 0 && array_key_exists('redirect_to', $_REQUEST)){             $redirect_to = $_REQUEST['redirect_to'];             $check_wp_admin = stristr($redirect_to, 'wp-admin');             if($check_wp_admin){                 wp_safe_redirect( '404.php' );             }         }     }       and the htaccess:               RewriteRule ^controlpanel/(.*) wp-admin/$1?%{QUERY_STRING} [L]      Now the confusing part is I have no idea how to do the same thing for wp- login.php. the changing from "wp-login.php" to "access" works but when wp- login.php typed, it is still accessible here's the code in the function file:               add_filter('site_url',  'wplogin_filter', 10, 3);          function wplogin_filter( $url, $path, $orig_scheme )     {      $old  = array( "/(wp-login\.php)/");      $new  = array( "access");      return preg_replace( $old, $new, $url, 1);     }      htaccess file:               RewriteRule ^access$ wp-login.php      So, my question is what to do to make wp-login.php not accessible (either redirected to 404 page or anything)? Any answers are very appreciated :) Thank you very much in advance


Set templates for custom post types

I am using Weaver II Pro theme 1.3.8 with WordPress 3.5.2 The theme is very flexible and provides many templates. On individual pages, I can even choose which template to use, which is cool and handy. Is there a way to assign a particular template for a particular custom post type, e.g. no sidebars for bbPress forum pages, or no sidebars for time.ly All-in-One-Event-Calendar, etc?


Site returns a 500 Internal server error

I have a serious problem with my WordPress theme. When I try to log in from Firefox, I will be logged in successfully but after that I try to log in with chrome or IE then I get 500 Internal server error. What am i doing wrong? I tried error reporting E_ALL, debug to true but no success. ![enter image description here](http://i.stack.imgur.com/3rJVd.png)


Wordpress Query based on random taxonomy

I am banging my head to get this solved, would appreciate if any one can help _**The scenario is,_**   * I have a WordPress site related to books.   * I have a custom taxonomy named "History Books" sluged as "history_books". under this particular taxonomy, I have many history books(terms).   * under my /assets/images/books folder, I have all the images related to specific booked (terms) i.e terms_hsb1.jpg _**What I want is,_**   * I need to run a RANDOM query based on my custom taxonomy " history_books", which should return a randomly selected term.   * Then I need to show the related image for that specific term.   * Total count of that terms   * A direct link to the term archive page. _**In Second Step,_**   * I want to show five post related to that specific term. I was trying many combinations, but nothing worked. Lately, I tried this code                           <?php                  $sugarquery = new WP_Query();                 $sugarquery->query( array( 'taxonomy' => 'history_books', 'orderby' => 'rand', 'showposts' => 1 ) );                 while( $sugarquery ->have_posts() ) : $sugarquery ->the_post();                 ?>                 <a href="<?php the_permalink(); ?>"><?php the_title(); ?>                      <?php                 $product_terms = wp_get_object_terms('history_books');                 if(!empty($product_terms)){                 if(!is_wp_error( $product_terms )){                 echo '
';                 foreach($product_terms as $term){                 echo '
slug, 'history_books').'">'.$term->name.'
';                  }                 echo '
';                 }                 }                      endwhile; ?>          I does query from specific tax, and returns one random post, but after that nothing happens. Please help me, what is the better way to get this done? BR


Automatically post to Google+ on new post

Is there a way to automatically post to Google+ whenever there is a blog post on WordPress? I found very conflicting information if that is possible or not. Ideally this should be free of course.


Wordpress Custom Rewrite Rule

I have a custom page template to use for a wordpress page. I am trying to setup a custom rewrite rule but without success. I have a page at blog/book-page/, the display of this page depends on the book id, hence I want url like blog/book-page/book-id/ to read the book id. In my functions php I have included the below function from Wordpress Codex:               add_rewrite_rule('^book-page/([^/]*)/?','index.php?page_id=11&book_id=$matches[1]','top');      But when I access http://xyz.com/book-page/123/, it keeps on redirecting me to http://xyz.com/book-page/ I refreshed the rewrite rules by saving the permalinks in the dashboard. Unable to solve by looking at similar questions at: Custom rewrite rule is not picked by Wordpress and Need help creating custom rewrite rule Any suggestions, Thanks in advance.


Custom field in a shortcode?

I cannot get the image from one of my fields into a shortcode.   (it works with `get_the_post_thumbnail($post->ID, 'thumbnail')` but I need the value from the field `udstiller logo`.               function logo_shortcode( $atts ) {         extract( shortcode_atts( array(             'limit' => '50',             'orderby' => 'name',         ), $atts ) );         // Creating custom query to fetch the project type custom post.         $loop = new WP_Query(array('post_type' => 'udstillere', 'posts_per_page' => $limit, 'orderby' => $orderby));         $output = '
';         // Looping through the posts and building the HTML structure.         if($loop){             while ($loop->have_posts()){                  $loop->the_post();                  $output .= '
ID,'wpcf-udstiller-logo',true).'"/>
';                  }         }         else             $output = 'Sorry, No projects yet. Come back Soon.';         // Now we are returning the HTML code back to the place from where the shortcode was called.         return $output;         $output = '
';     }     add_shortcode("Logo", "logo_shortcode");


How to get Poster (thumbnail) Image of Video

I'm getting all videos using the function below and it's working fine. Now I want to get the videos Poster Image (Thumbnail Image) from that video. How can I get the video Image as thumbnail? I've also tried to get thumbnail by this function but It's not working                   $page_id = 659;          $page_data = get_page( $page_id );               if (has_post_thumbnail( $page_data->ID ) ){ ?>         <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page_data->ID ), 'single-post-thumbnail' ); ?>         <img src="<?php echo $image[0]; ?>" width="200" height="212" />         <?php }?>      I'm getting all videos by this function                   $args = array                 (                     'post_type' => 'attachment',                     'post_mime_type' => 'video',                     'order' => 'DESC',                     'orderby' => 'post_date',                     'posts_per_page'  => -1                 );                 $videoFiles = get_posts($args);                  foreach ($videoFiles as $file) {         }      My post object:               WP_Post Object     (         [ID] => 670         [post_author] => 1         [post_date] => 2013-06-26 10:55:51         [post_date_gmt] => 2013-06-26 10:55:51         [post_content] => Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries,         [post_title] => Strike Back         [post_excerpt] => Composer         [post_status] => inherit         [comment_status] => open         [ping_status] => open         [post_password] =>          [post_name] => columbia4x3         [to_ping] =>          [pinged] =>          [post_modified] => 2013-06-26 10:55:51         [post_modified_gmt] => 2013-06-26 10:55:51         [post_content_filtered] =>          [post_parent] => 0         [guid] => http://host.com/wp-content/uploads/2013/06/Columbia4x3.mov         [menu_order] => 0         [post_type] => attachment         [post_mime_type] => video/quicktime         [comment_count] => 0         [filter] => raw     )


Creating Pages within a secure folder outside the normal wordpress folder

I have a members site where the members material is in a folder in root called secure. Access is controlled by a separate billing company and protected by strongbox. I m re designing the site using wordpress and have set up wordpress in a folder called mywp. I would like to make update pages that are only available in the secure folder once members have logged in but cannot find any clear instructions on how to do this. Any suggestions or solutions are appreciated.


Viewing statistics on self hosted site from Android WordPress app

I did / do have a WordPress hosted blog (with statistics working fine). I've now set-up a self hosted blog and have paid for an off-site redirect from WordPress to my new blog. That all works fine. If I log onto my self hosted admin page I can see the sites statistics, but I'm asked to log in again, this is odd, but I do get to see the statistics. However, when I'm using the WordPress for Android (1.3.7) application and I log onto my self hosted site I see no statistics unless I go to the year view. This seems to then show me the statistics from the WordPress site, but not my self hosted site. How can I fix this?


admin-ajax.php vs .load() in WordPress

I'm developing a theme and I want to ajaxify each internal link in my theme. Uptill now, i've used `admin-ajax.php` method successfully for these actions ... 1: Load More Posts for Blog with Ajax 2: Open Single Blog Post with Ajax And i've used seperate .js scripts and ajax callback function for each of the above action. But the issue is if i want to ajaxify whole of my wordpress theme i'll have to code many such scripts and callback functions for each internal link e.g author page, search page, default page template, custom page template ... etc. Now, i want to ask ... 1: Is it the only way to ajaxify your whole site or if there is any better way? Cannot we use `.load()` method with less usage of code? (as in `.load()` method we only have to specify the URL to load irrespective of the fact that which page we are loading) 2: Why `admin-ajax.php` method is preferred vs `.load()` method?


Disallowing Users of a Custom Role from Deleting or Adding Administrators?

_( **Moderator's note:** The original title was "Custom User Role Restrictions")_ A project I am working on requires me to create two new user roles - one for the owner of the website and the other for agents of the company. With the website owner user role I was just looking for a way to restrict users in this group from modifying core site settings while having access to modify all other settings. The code below seems to work perfectly for everything other than the user management area. I did want users of this group to be able to add/modify website users BUT where I am running into a problem is that users of this group currently have the ability to create users in the _"Administrator"_ category and they are also able to deleting existing _"Administrators"_. What I am looking for is a way to modify the code below so that such users can NOT delete or modify a user account which is set as _"Administrator"_ and restrict the user from being able to create a new Administrator account. Does anyone know how this can be done?               // CREATE CUSTOM - SITE OWNER - USER ROLE WITH CUSTOM CAPABILITIES     if (!get_role('website_owner')) {       //let's use the editor as the base capabilities       $caps = get_role('editor')->capabilities;        $caps = array_merge( $caps, array(         'install_plugins'               => false,         'activate_plugins'              => false,         'update_plugins'                => false,         'delete_plugins'                => false,         'list_users'                    => true,         'add_users'                     => true,         'create_users'                  => true,         'edit_users'                    => true,         'delete_users'                  => true,         'remove_users'                  => true,         'unfiltered_upload'             => true,         'install_themes'                => false,         'update_themes'                 => false,         'delete_themes'                 => false,         'switch_themes'                 => false,         'edit_theme_options'            => true,         'manage_options'                => false,         'import'                        => false,         'update_core'                   => false,         'edit_dashboard'                => false,         'gravityforms_view_entries'     => true,         'gravityforms_edit_entries'     => true,         'gravityforms_delete_entries'   => true,         'gravityforms_export_entries'   => true,         'gravityforms_view_entry_notes' => true,         'gravityforms_edit_entry_notes' => true,         'gravityforms_feed'             => true,       )); //adding new capabilities.       // Ref: http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table       add_role( 'website_owner', 'Website Owner', $caps );     }


Removing container from wp_nav_menu not working

I'm converting this html menu to wordpress:

Home

About

      i use:               wp_nav_menu(array(      'menu'=>'mainmenu' ,      'container'       => false,       'link_before'     => '',      'link_after'      => '',      'theme_location'  => 'primary')      );      but the html i get is:

Home

About

      If i use a custom menu then i get:

Home

About

      but if i don't use a custom menu 'container'=>false doesn't work Any solution?


How do I display Youtube/Vimeo video ID on custom post type when user enters it in custom meta box?

I have created a 2x shortcodes that displays a youtube video and vimeo video when the user enters the videos id in it, for example: [youtube id=""] [vimeo id=""]. Instead of entering this in my post I am trying to create a custom meta box that the user can enter the id in and then this is displayed. So far I have been able to create a plugin to display the meta box but I'm not sure how to get it to save the youtube/vimeo ID and display the video. Will I need 2x different meta boxes? One that the user can enter the youtube video ID in and the other where the vimeo ID can be entered and then this is displayed on the front end? The code I have for the meta box is:               add_action( 'add_meta_boxes', 'cd_meta_box_add' );     function cd_meta_box_add()     {         add_meta_box( 'my-meta-box-id', 'Enter Video ID', 'cd_meta_box_cb', 'videos', 'normal', 'high' );     }          function cd_meta_box_cb( $post )     {         $video_type = get_post_meta($post->ID,'my_video_type',true);         $video_id = get_post_meta($post->ID,'my_meta_box_text',true);         wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );              ?>
             Select video type:                           <select name="my_video_type" id="my_video_type">                   <option <?php echo ($video_type == 'youtube') ? "selected='selected'" : "" ;?> value="youtube">Youtube</option>                 <option <?php echo ($video_type == 'vimeo') ? "selected='selected'" : "" ;?> value="vimeo">Vimeo</option>             </select>

             Youtube/Vimeo ID:             <input type="text" name="my_meta_box_text" id="my_meta_box_text" value="<?php echo $video_id; ?>" />
                        <?php        }               add_action( 'save_post', 'cd_meta_box_save' );     function cd_meta_box_save( $post_id )     {         // Bail if we're doing an auto save         if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;              // if our nonce isn't there, or we can't verify it, bail         if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;              // if our current user can't edit this post, bail         if( !current_user_can( 'edit_post' ) ) return;              // now we can actually save the data         $allowed = array(              'a' => array( // on allow a tags                 'href' => array() // and those anchords can only have href attribute             )         );              // Probably a good idea to make sure your data is set         if( isset( $_POST['my_meta_box_text'] ) )             update_post_meta( $post_id, 'my_meta_box_text', wp_kses( $_POST['my_meta_box_text'], $allowed ) );               }     ?>      In single.php I need to run a query to display the video based on what the user enters in the meta box. My code for that is:               <?php global $post; ?>     <?php                                       if(get_post_meta($post->ID,'my_video_type',true) == "youtube"){                                 $youtube_id = get_post_meta($post->ID,'my_meta_box_text',true);                                      }                                 if(get_post_meta($post->ID,'my_video_type',true) == "vimeo"){                                     $vimeo_id = get_post_meta($post->ID,'my_meta_box_text',true);                                    }                                 ?>      However this does not display anything. I have been pulling my hair out to get this sorted. If anyone can help it will be greatly appreciated. Thanks in advance.


How to forbid users to change their first, last and screen names?

I'm using Wordpress 3.1. I need to forbid users to change their first, last and screen names in their profile, but admin must still have this possibility. How can I do that?


Is there any free (or cheap) software that can be used for testing WordPress functionality? I would like to create some test scripts and then them against my self-hosted WordPress installation.


How to prevent redirect to 'About' after core upgrade?

In `wp-admin/includes/update-core.php` we find the following line:               add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );      I want to remove this action, so I created a mu plugin with the following content:               <?php # -*- coding: utf-8 -*-     add_action( '_core_updated_successfully', 't5_no_redirect_after_update', 0 );          function t5_no_redirect_after_update()     {         remove_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );     }      It does … nothing. I am still redirected. Tested with single site and multi site installations. I guess I miss something obvious, as usual. :)   How to do it better? ## Update Based on Brady’s answer I build a very minimal version:               <?php # -*- coding: utf-8 -*-     /* Plugin Name: T5 No redirect after core upgrade. */     add_action( '_core_updated_successfully', 't5_no_redirect_after_update', 0 );          function t5_no_redirect_after_update()     {         show_message( __('WordPress updated successfully') );              // Include admin-footer.php and exit         include(ABSPATH . 'wp-admin/admin-footer.php');              exit;     }      Now we see the success message and no other action is called. You can download the plugin on GitHub. Use it as regular plugin or as MU plugin.


paginate_links() on page (shortcode output)

On a standard WordPress page, I have a `WP Query` that runs through a post type I created. Along with that query, I am using paginate_links() to generate pagination. While the standard (no permalinks) seems to work fine - when enabling any permalink combination, the subsequent pagination pages do not load. Here is what I have so far:               $post_args = array(         'post_type' => 'galleries',         'paged'     => get_query_var('paged'),         'post_type' => 'galleries'     );          $posts_query = new WP_Query($post_args);     $i = 0; // count     $total_items = $posts_query->post_count; // total profiles     $number_columns = $galleries_options['columns']; // number of columns     if ($posts_query->have_posts() ) {         echo '
';         while ($posts_query->have_posts() && ($i < $total_items)) { ?>             <?php $posts_query->the_post(); if ($i % $number_columns == 0) echo ($i > 0 ? '

' : '
'); ?>             <div class="<?php echo 'width'.intval(100 / $number_columns); ?> <?php if ($i % $number_columns == 0) echo 'first-item'; ?>">                 <?php                     galleries_list(get_the_ID());                 ?>
         <?php $i++;         }         echo '
';         echo '
';              $total_pages = $posts_query->max_num_pages;         $big = 999999999; // need an unlikely integer          if ($total_pages > 1){               $current_page = max(1, get_query_var('paged'));               echo '';               echo paginate_links(array(                   'base'      => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),                 'format'    => '?paged=%#%',                   'current'   => $current_page,                   'total'     => $total_pages,                   'prev_text' => 'Prev',                   'next_text' => 'Next'               ));               echo '';           }           }      The default URL is `?page_id=60&paged=2` which works/loads fine - yet `galleries/page/2/` does not. Anyone have any suggestions? I'm using the exact same thing for taxonomy pagination... so I'm a bit confused on why this isn't working. Thanks!


How to add GET variable after script url?

So, I've registered and enqueued my script. `http://mysite.com/wp-content/plugins/my-plugin/script.js?ver=3.6` But how do I add a GET variable on the script src url? `http://mysite.com/wp-content/plugins/my- plugin/script.js?ver=3.6&myVar=whatever` Any help appreciated.


Post title not output correctly

I am trying to set up titles of posts with WordPress SEO, however my title gets output like this: My post name There is no separator and site name. Here's the code in the theme:                 <title><?php wp_title(''); ?></title>      In the WordPress SEO settings, under Post Types > Posts I have the following setting for titles: %%title%% %%page%% %%sep%% %%sitename%%


add youtube thumbnail in index and single.php add video

I crating custom wordpress themes for video related website, client can embed youtube video, in index.php only show thumbnail image and title of video then when click thumbnail it goes to single.php & show the video, Plase any one help me, I try Video Thumbnails it not work me.


Rendering of custom walker menu function not working properly

I have a custom function for my nav walker menu that adds custom php/html to it, which can be seen below. It renders a twitter bootstrap dropdown menu that I would like to put my login form in.                   function add_login_logout_link($items, $args) {             if ( is_user_logged_in() ) {                 $items .= '

' . __('Log out', NOVALANG) . '
';             } else {                 $items .= '

Skapa konto

                         ' . __('Log in', NOVALANG) . '

' . get_template_part('login') . '

Jag har glömt lösenordet

';         }         return $items;         }         add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 4);      The problem here is the rendering of the custom login form using get_template_part('login'), which shows up in the top of the page where it really should not be as far as I can see.

      It's empty! And the login form shows up in the header. I have that code in a separate php-file, but I don't think that is the problem because I have tried rendering it using other code in a custom function in the functions.php-file. Anyone who can point me in the right direction?


Localized Date Format for Custom Field

I'm using a custom field, formatted with "dd-mm-yyyy". I would like to use it with the Date Format defined in the Dashboard settings. It seems alright in English with               get_option('date_format');      Or manually in French with               setlocale(LC_ALL, 'fr_FR');     $date_local = strftime("%d-%m-%Y",$date->format('U'));      But is there a way to use the localized date format of wordpress? I can't find how to give the date as an argument to               the_date()


wp_mail - using a custom field value for $to

I'm trying to pass a custom field value to my functions.php file. I want to replace: $to = get_bloginfo( 'admin_email' ); to something along the lines of: $to = get_custom_field('sendto', TRUE); So the user will have a recipients field on their post (custom post type) that they can add email addresses to, then when the post is published, those users will receive the notification as well. Thank You for any help.


Interface for logged-in users to upload/download files

I am setting up a site for a non-profit that would like to have a 'members' area where certain users can swap files for meetings, events, etc. They essentially need a simple interface where they can upload/download files --one that is removed from the WordPress admin area. Some info:   * They would be uploading mostly text documents, so I am not worried about a high-capacity solution. The server I have for the website would definitely be able to handle the load    * There are about 30 members    * A secretary would look after the creation/removal of members    * It would be nice to be able to embed it into the site using some sort of plugin, but I am not against using a 3rd-party service either The only solutions that are looking good so far are Dropbox Teams or Box.com Business, but they seem quite extreme for this organization's needs. I also came across Wuala. I've never heard of it before, but the prices are much cheaper than the alternatives. Does anybody have experience with this kind of problem? :) Thanks a lot!


Copyright: Get first and last date of post type

I was searching for the easiest/fastest way to get the accurate date range for copyright notices in the footer. The copyright notice shouldn't only contain the year, but as well take month and day into account and consider the post type. So a custom post type of "Event" could have a different copyright date range than a blog "post" post type.


WordPress Images | How to get the cropped image?

I have the URL of an image (full size). During the upload it already generates a smaller version (I added this in functions). How can I get this cropped version when I have the full size URL? The Image is not in a post so I can't use `post-thumbanil()`. The image is in a slider on the Homepage.


"Error parsing the WSDL file:" Web service plugin in Wordpress

I am new at using Wordpress and using this plugin guide (WordPress Web Service Plugin) to activate the plugin to use over Web Service in Wordpress. After followed the procedures, an error showed up, even when I tried on _localhost_. It showed like this, not like in the instruction.. :( ![WSDL Fail, shouldn't be like this](http://i.stack.imgur.com/7keRw.png) Maybe someone could try it since it's easy to follow, but somehow different in result.


How can I stop WordPress from catching URL's for static pages that I save on my server

I posted a question about whether it's possible to add a Page in WordPress without headers and footers. Here's that question: Add a Page without header and menus? So how can I create a static page with none of the WordPress stuff that appears on all the other pages of my WordPress site, and add html at that url? How would I do that?


Add a Page without header and menus?

Is it possible to add a Page in WordPress, so that none of the header or the menus of the site appears on that page? And also so that the stuff in sidebars that's on the rest of the site doesn't appear. And the stuff at the bottom of the page (there's a 'Leave a reply' form on the other pages.) So on this site: http://richardclunan.com/ don't want any of the header handwriting or the 'hey there' / 'portfolio' / 'need copywriting' / 'etc' menu items to appear on one particular page, nor the side-bar sign-up box, nor the 'leave a reply' form. But I want all that stuff to appear on all other pages.


Can't iterate through 2 levels of categories

I purchased a Wordpress theme, for a restaurant. The theme uses Posts for each (food)menu entry, and Categories to segment the menu into sections. The theme is built for 1 level hierarchies. e.g:               >Menu     >>>Breakfast     >>>Lunch     >>>Dinner      However, the restaurant I am working for has a more complex menu:               >Menu     >>>Breakfast     >>>>>>Food     >>>>>>Sides     >>>>>>Drinks     >>>Lunch     >>>>>>Small     >>>>>>Large     >>>>>>Sides      Here is the original index.php Here is my modified index.php, which attempts to iterate first within the 1st level of categories (e.g. Breakfast, Lunch...), and then through all 2nd level categories (e.g. Breakfast > Food, Breakfast > Sides...). In both, $menuCat refers to the "Menu" parent category. This is the live site, using a child theme, and the new index.php. It manages to find the "Lunch" category, but not the "Breakfast" category, and it doesn't output the subcategories. I receive a PHP exception: > Warning: Illegal offset type in isset or empty in /.../wp- > includes/taxonomy.php on line 1236 Here is taxonomy.php from line 1234:               if ( $parent ) {         $hierarchy = _get_term_hierarchy($taxonomies[0]);         if ( !isset($hierarchy[$parent]) )             return $empty_array;     }      So, it seems the $hierarchy of the parent is not not set. I don't know what this means.


typeerror this.getdoc(...) is undefined wordpress

I have face this issue after upgrade WordPress 3.0 to 3.5.1 . Can anyone guide me how can I fix it. My all tinymce editor stop working after upgrade.


Pagination working locally but not on live site

I have a loop on my single.php page like this:-               <?php if (have_posts()) : ?>              <?php $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; ?>              <?php $this_post = $post->ID; query_posts( array('meta_key' => 'epicredrank', 'orderby' => 'meta_value_num', 'order' => 'DESC' , 'paged' => $paged, 'category__in' =>  wp_get_post_categories( $post->ID ), 'post__not_in' => array($this_post),  ) ); ?>                             <?php while ( have_posts() ) : the_post() ?>                             <?php if ( has_post_format( 'video' )) {                      get_template_part( 'video-post' );                 } elseif ( has_post_format( 'image' )) {                     get_template_part( 'image-post' );                 } else {                    get_template_part( 'standard-post' );                 }                  ?>                   <?php endwhile;?>              <?php endif; ?>      This works on my local installation to paginate posts on single.php but not on the live server and I can't work out why. Have tried saving permalinks etc... EDIT:- If I use the permalink structure 'default' it works just fine, but it fails on pretty permalinks.


Pass PHP variable to javascript

Is there any possibility to pass some PHP variables in javascript so I can use them later? Only in `single.php`.   I heard about `wp_enqueue_scripts` but with that it is neccesary to declare a path to a JS file, but I don`t need one.


How to display Multi Checkbos select Custom Field on the post?

i have create a Custom Post Type calle "Places". I have created a Custom Field with Field Type "Multi CheckBox" Option Title "Type of Pub" Option values "Sports, Rock, Biker, Beer, Live Band, Restro, Gastro, Irish, Karaoke Bar" Field Title "Type of Pub" Field name "typeofpub" When i Add New Places, Type of Pub with Values with checkbox shows up on edit page. I selected all the values (Sports, Rock......) How do i call the metadata to display is custom field on a post.


Index template and Home page

Sorry if this seems silly but I am new to WP. I realise that Index template is the most important file. Is it ok to have Index as your "home" page, and can you just assign the Index template to the home page when setting it up in the back-end?


Is there a widget that can display a certain Custom Post Type Terms?

I am looking for a widget that a user can choose a Custom POst Type Term from a list. As an example I have a Custom Post Type called events and it has multiple categories. I want the user to be able to choose to show only posts from a certain category. Does anyone know of one or know how I can make this please?


User Signup in Multisite - Need Plugin or Advice

I'm trying to make some modifications to a wordpress multisite and i could use some help from someone more experienced. I want to restrict the acces to my blogs unless the user has an account. In detail : i have a series of blogs, each one with an admin/autor. If a user wants to read posts from a blog, he should first go on the main site, to wp-signup.php and create an account. I'm planning on creating a plugin, active on all subsites. Is this possible? if yes, could someone give me some directions - wich hooks, filters and functions i would need ? Thank you!


Global searchin multisite but only with one subsite

I have a multisite set up with currently 2 subsites. Is it possible to have a search box that searches the main site and just one subsite?


How do I apply a template to my single posts?

(I am using a child theme of twenty-ten) For most of my pages I like to use the single column template. I noticed that (after I updated to 3.14) my single posts were using the default template (which has a sidebar for widgets). How do I get rid of this? I could style the sidebar away but is there a way to tell WP to apply the single-column template for my single-posts? Note that the main blog page applies the single-column template to it, so this is only happening when I bring up individual posts.


Creating an "admin only" meta box with WPAlchemy. Getting a fatal error on front-end when using current_user_can

I'm trying to create an "admin only" meta box using WPAlchemy. The box for example may contain a "feature post" check box and other functionality. How can I show this meta box for only the admin, yet have it work properly? I'm currently using the following code below, but I receive a "Fatal error: Call to a member function the_meta() on a non-object" when trying to echo the value of whatever is inside on the front-end. Everything works as intended if I don't use current_user_can and works also if I'm logged in as admin and viewing the front-end.               if (current_user_can('administrator')) {     $custom_admin_mb = new WPAlchemy_MetaBox(array(         'id' => '_custom_admin_meta',         'title' => 'Admin only',         'template' => TEMPLATEPATH . '/custom/admin_meta.php',     ));      }


How to modify the comments to be displayed in a post?

I would like to know how to modify the way wordpress displays the comments in a page. The requirement at hand is to display a certain number of comments in the comments list and while the the user scrolls to the bottom of the comments list (not on the page), a new set of comments will be appended to the comments list (if there are more comments to be displayed). I have the following code to call the comments to be displayed:               <?php     require_once("../../../wp-config.php");          $page = $_GET['cpage'];     if(isset($page))     {         echo loadComments($page);                               }          function loadComments($page=1)     {         global $wpdb;                 $number=5;             $result='';              // get comments from WordPress database          $numRows = $wpdb->get_var("SELECT COUNT(*)                                 FROM $wpdb->comments                                  WHERE comment_approved = '1'                                      AND NOT (comment_type = 'pingback' OR comment_type = 'trackback')");                          if ($numRows > $number)         {                 $nav=1;                 $pages=ceil($numRows/$number);         }         else {             $nav=0;             $pages=0;         }              $getnumber=$number*$page;              // get comments from WordPress database          $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments                                          WHERE comment_approved = '1'                                              AND NOT (comment_type = 'pingback' OR comment_type = 'trackback')                                         ORDER BY comment_date_gmt ASC                                          LIMIT $getnumber");                   $comments=array_slice($comments, $getnumber-$number, $number);                   if ( $comments )         {             $count=1;                  // display comments one by one             foreach ($comments as $comment)             {                   if ($page <= $pages)                 {                     $result.= '
comment_ID.'" class="leftcolumn">

'.                             '

'.$comment->comment_content.'

'.                             '

'.                             '

'.'

'.                             '
comment_ID.'">'.'
'.                             ''.$comment->comment_author.'

'.                             ''.mysql2date('j-n-Y',$comment->comment_date).''.                             '

'.                             '

';                                     $count++;                           }                else                {                 $result = '';                }             }         }            return $result;     }          ?>      and this is the ajax call to append a new set of comments:               function updatestatus(){         //Show number of loaded items         var totalItems=$('.commentlist li div.commenttext').length;         $('#status').text('Loaded '+totalItems+' Items');     }          function scrollalert(){         var scrolltop=$('.commentlist').attr('scrollTop');         var scrollheight=$('.commentlist').attr('scrollHeight'); //825         var windowheight=$('.commentlist').attr('clientHeight'); //600         var scrolloffset=20;         //alert(scrolltop);         if(scrolltop >= (scrollheight - (windowheight + scrolloffset)))         {             //fetch new items             if (count > 0 )             {                 count++;                 $('#status').text('Loading more items...');                 $.get('/wp-content/themes/twentyten/commentloader.php?cpage='+count, '', function(newitems){                                if (newitems != '')                     {                         $('.commentlist').append(newitems);                         updatestatus();                                         }                        else                     {                            // prevent from appending content                         count = -1;                     }                 });            }            else            {                 $('#status').text('No more items to load...');            }         }            setTimeout('scrollalert();', 1500);     }      I tried adding the two files inside the themes folder and adding a reference to header.php for js file. This works but I have to set paging on for the comments and hide the navigation. If you could provide a better way to achieve (may be create a plugin?) I will greatly appreciate it. I am new to WordPress and will be delighted if you'll lead me to the right direction. Thanks, RNorbe


Sticky Posts & Posts Per Page

I notice that sticky posts will disregard the `posts_per_page` param? Like I have a query like               $q = new WP_Query(array( 'posts_per_page' => 4, ... ));      If there are 3 sticky posts, I will get 6 posts? (its abit strange tho why 6 not 7 (4+3)) I dont want to ignore sticky posts. How can I force the posts per page limit? eg, I have 10 sticky, I still get only 4 posts. One way I can think of is a counter that counts to 4 and exit the loop. But there isnt a WP way? This appears to be more of a bug to me?


Can I specify template to use with the_permalink?

Can I specify a template to use with the_permalink()? Why I need this: when they click a link from a certain page, I want to show that user a different template (extra content) on the linked page.


pages won't show on front page using loop or pre_get_posts

I changed up my theme to work what I think is the "proper" way. After reading in the codex and seeing things on this site. I started from scratch. loaded the 2012 theme. Made two pages. Home and blog. I set the homepage to have the default 2012 front-page.php template. then in the settings->reading I set static front page to home and posts page to blog. I know the posts will be pulled from the index.php so in that file, I put the custom loop to pull from the blog category and in my front-page.php file I put a custom loop to get pages.                $args = array(         'post_type' => 'page'      );            $page_query = new WP_Query( $args );            if ( $page_query->have_posts() ) : while ( $page_query->have_posts() ) :   $page_query->the_post();       $template = get_post_meta( $post->ID, '_wp_page_template', true );       // If the page doesn't have any template assigned - display the default page template         if ( $template == 'default') { ?>
<?php the_title();?>
                 <?php the_content(); ?>         <?php   }  else {             include( $template );         }         endwhile;        endif;      This loop was working just fine in other versions of this theme but for some reason, set up the way it is now which is suppose to be the right way, it's not working. I also tried using pre_get_posts to display pages on the front- page. ?>


send bulk emails without timeout

I am developing a plugin that sends emails out to users. I am having difficulty in finding the most performance enhanced way to send these emails out and prevent a server timeout. In other words, I would like my plugin to scale, so if someone that uses it on a site with a hundred thousand users, my plugin will still work. Perhaps there is a way to execute each email or two as a separate script that gets executed one after another? Some help/insight on this would be appreciated. Thanks


Set default text for the editor in new posts

I was wondering, is it possible to set default text to appear inside "text" part of the wysiwyg located on Create post page? So every time you click add new post that text would be there waiting for you?


Register a widget area when a theme option has been saved?

Is it possible to register a widget area and sidebars when an option has been selected and saved in a theme options panel? I am using a framework called redux but am not too sure if this can be accomplished as I am unsure on whether there is a hook that would be available to register the widget area / menu.


How to find what index page a post is on?

Here is a simple example of what I am wanting to figure out. Say I have WordPress set to show 5 posts per page. And say I there is a post 17 posts back chronologically. The formula would be 17 / 5 = 3.4. Round up 3.4 to a whole page of 4 and that post 17 posts back is on the 4th index page. Now... How to do this programmatically... The number of posts on each index page is determined by the `get_option( 'posts_per_page' );` option. If all I have is the post's id, how do I figure out how many posts back it is chronologically? My head first went to `WP_Query`, but it is not a suitable option. The blog this is for has thousands of posts and it runs out of memory before I can get anywhere to determine where the post is at. Does anyone have an clever suggestions?


Why did installing wordpress in url root jack up underlying WP sites?

I have a server (w2008 with iis7.5) and domain with a lot of different WP installs. > All of the following represent WP installations. > >   * x.com/stuff >   * x.com/programs/recent >   * x.com/programs/asia >   * x.com/sandbox/1 >   * x.com/sandbox/2 >   * x.com/requests > I have been redirecting x.com to y.com for some time now - with only the WP subsites in use but would like to take off the redirect and start using the root url. However when I install WP (fresh 3.8.1) in the root (inetpub/wwwroot) it basically breaks every website that I have. I was having various issues, from the site not coming up, to permalinks not working, to not being able to get theme files. I tried taking out the web.config files on each install and those not coming up came up but of course the permalinks weren't working. What are the steps I need to do to get the root working without killing the rest of the WP installs? On one of the older WP installs that only works with the default permalink and when I set it to default in WP admin it changes the web.config to the follow:               <?xml version="1.0" encoding="UTF-8"?>     <configuration>       <system.webServer>         <rewrite>           <rules/>         </rewrite>       </system.webServer>     </configuration>      When I change the same site to year/month/name in the WP admin it sets the web.config to this:               <?xml version="1.0" encoding="UTF-8"?>     <configuration>       <system.webServer>         <rewrite>           <rules>                 <rule name="wordpress" patternSyntax="Wildcard">                     <match url="*"/>                         <conditions>                             <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>                             <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>                         </conditions>                     <action type="Rewrite" url="index.php"/>                 </rule></rules>         </rewrite>       </system.webServer>     </configuration>      This totally messes up the site (doing this used to work). The site looks like it doesn't have css or correct paths plus any link needing the rewrite doesn't work. **Also note that I do change the name of the rule so it doesn't conflict with other wordpress sites. So this one is wordpress_22 - I just copied what WP actually creates.** However on a WP install from last week - on same server just one directory over using year/month/postname I get a web.config:               <?xml version="1.0" encoding="UTF-8"?>     <configuration>       <system.webServer>         <rewrite>           <rules>                 <rule name="wordpress" patternSyntax="Wildcard">                     <match url="*"/>                         <conditions>                             <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>                             <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>                         </conditions>                     <action type="Rewrite" url="index.php"/>                 </rule></rules>         </rewrite>       </system.webServer>     </configuration>      This site works perfectly fine. I can change the permalinks whatever way and they all work... riddle me that.


Show post categories

I'm trying to show post categories for some breadcrumbs. At the moment, I have this:               the_category(' / ', 'multiple');      But for some reason, it is stating the parent category twice (I only want `parent > child`):               FASHION / DAILY FASHION CANDY / FASHION      It should really be:               FASHION / DAILY FASHION CANDY      Would anyone know why it's doing this, and how to change it?


Dashboard - get status and position of metaboxes and pass them to ajax method

I'm wondering if it's possible to get status and position of metaboxes added to a dashboard-like page. The main page of my plugin has several metaboxes laying in a two-columns page and a "table of content" box on top (with internal links, like a wikipedia page). However, since you can order/hide/reveal a metabox, the TOC box should be updated accordingly via an ajax method. Is it possible to trigger a method like that, passing all parameters i need to accomplish the ordering (position and status of all metaboxes)? tnx in advance, Gabriele


Add text to Text Widget using Javascript

Wordpress has a Text Widget (at least the theme I'm using does, and I think they all do?) In this widget I can add text or HTML. If I add HTML I can include JavaScript. This works fine (I'm hosting my own site). I want to add some text to the Widget using a script. However; document.write("Whatever") writes the text onto the actual web page. What command do I use to write text into the Text Widget only. Many thanks for any help!


Custom field in external Javascript

How do I use a custom filed value in an external javascript? I'd like to use a custom field already stored for a post that is an url in an external javascript               <script type='text/javascript' src='http://www.my-website.com/wp-content/themes/mytheme/js/scripts.js'></script>      in order to open a new window               onclick="window.open('MY_CUSTOM_FIELD_VALUE');"      I tried to add               global $post; $cf = get_post_meta( $post->ID, 'my_custom_field', true );      but it doesn't work. Thanks for your help.


Custom post type or just use custom fields

I am turning a restaurants website into a wordpress website to allow for the customer to take over content changes. The restaurant has a menu that has categories like Baskets with different types. For instance under the Basket type there is Fish which has a Title, Description, and Price. So what I want to do is to be able to have the customer create or delete Menu categories and have the ability to create,delete, update menu types. Then the entire menu is shown on one page. You can view the page at www.tailfinstogo.com/menu.html.


Custom Post Type for displaying products in a database table

I have a WordPress project that I'm using as a CMS. ~~I also have a database with some products in it that I'd like to display on the site (gallery or portfolio maybe?)~~ I have a custom post type for Products that I want to be editable in the wordpress admin (along with the rest of the content). ~~I know I have to do a custom post type (which I'm reading up on, probably will use Simple Fields plugin) but I'm not seeing a way to pull these values from a database.~~ Products will have ProductName, URL, Category, and Type. I would want to list and add/edit/delete these in the word press admin side of course. Any advice will be greatly appreciated. Thank you all! EDIT: I've created the Custom Post Type for `Products`. Now each `Product` can have a `Category`, `Subcategory`, and `Type`, which I'm assuming will also need their own Custom Post Type if they are to be manageable right? The layout for the products will be roughly: `ProductName`, `Type`, `Category`, `SubCategory`, `Document Name`, `Document URL`. Remember the `Category`, `SubCategory`, `Type` will need to be manageable and editable so I guess they will need to be custom post types as well. Thinking about this some more, could I use the built-in categories for MY custom post type categories and have the subcategories as children of the main categories? That might be the easier way out on that end. But how would I map a custom post type of `ProductType` to my custom post type of `Product`? Here is my product custom post type:                   /*  CUSTOM POST TYPE AREA FOR PRODUCTS   */     add_action( 'init', 'create_product_post_type' );          function create_product_post_type()      {         $labels = array(             'name' => _x('Products', 'post type general name'),             'singular_name' => _x('Product', 'post type singular name'),             'add_new' => _x('Add New', 'products'),             'add_new_item' => __('Add New Product'),             'edit_item' => __('Edit Product'),             'new_item' => __('New Product'),             'view_item' => __('View Product'),             'search_item' => __('Search Products'),             'not_found' => __('No products found'),             'not_found_in_trash' => __('No products found in Trash'),             'parent_item_colon' => '',             'menu_name' => 'Products'                        );              $args = array(             'label' => __('Products'),             'labels' => $labels,             'public' => true,             'can_export' => true,             'show_ui' => true,             '_builtin' => false,             'capability_type' => 'post',             'menu_icon' => get_bloginfo('template_url').'/functions/images/product.png',             'hierarchial' => false,                 //'rewrite' => array( "slug" => "events" ),             'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),             'show_in_nav_menus' => true                  );                  register_post_type( 'tf_events', $args);         }