INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Keyboard shortcut for headings on safari When I use wordpress on PC, I can simply press ctrl+1 for Heading1 and ctrl+2 for heading 2... But when I use my mac it doesn't work. What are the shortcuts for heading styles on safari?
Short answer- there aren't any. If you click the help button in the editor, then the hotkeys tab, you'll see the available shortcuts for the current OS/Browser. In OS X the modifier is Command instead of Control, but there aren't any shortcuts for headings.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, tinymce, editor, visual editor" }
How to create Sub Sub domain Multi User blogs? Hi to all I would like to create a big Wordpress network with this structure: * sitename.com (Main website) * cat1.sitename.com (sub website) * cat11.cat1.sitename.com (sub-sub website) * cat12.cat2.sitename.com (sub-sub website) * cat2.sitename.com (sub website) * cat21.cat1.sitename.com (sub-sub website) * cat22.cat2.sitename.com (sub-sub website) * cat3.sitename.com (sub website) * cat31.cat1.sitename.com (sub-sub website) * cat32.cat2.sitename.com (sub-sub website) Is it possible using only one wordpress installation with subdomains? If it is not is it possible to share userdatabase (and why not also posts and all the stuff) between all the websites? Is there anyone that already did it and can help me to achieve this? Thank you very much!
While this question is several months old and you've probably figured something out already, I figured it was worth answering anyway. This is possible to do using the WP Multi Network Plugin. WordPress has the underlying structure to accomplish this, but no accompanying UI -- this plugin merely offers that interface. Some things are not completely shared across _Networks_ , and I believe Users are one such example. If I remember right, users can span multiple networks, but it needs to be done by a super admin. Anyway, play around with it, you'll get it working how you want! Cheers~
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "php, multisite, database, subdomains" }
Automatically load Wordpress page on server every XX hours I have a page in my Wordpress site that calculates post popularity and updates several meta fields on the posts and calls a few functions as well. This page is set to "Private" so that only myself and other admins can see it. Is there a way to load this page automatically every 6, 12, or 24 hours? I'd be satisfied with a plugin, but generally prefer to write my own PHP code.
You could use the WP-Cron functions to scheduled events. Note though that this is pseudo-cron- it requires someone (or a bot) visit your site for the events to execute. To fire events more reliably, search for scheduling cron jobs (linux) or scheduled tasks (win). Depending on your hosting, you may have access to simple tools to schedule events, for example cPanel has a GUI for setting up cron jobs.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, server load" }
What function actually renders the wp_admin_bar ? How can I call it? What function actually renders the wp_admin_bar? And how can I call it? I want to print out just the nodes / DOM for the actual menu. It would end up rendering something like this: <div id="wpadminbar"> <div class="quicklinks"> <ul> .... </ul> </div> </div> I couldn't find it in the documentation anywhere.
WordPress admin bar is rendered by `render()` method in `WP_Admin_Bar` class, also you may need to check `wp_admin_bar_render()`, it add few hooks before and after rendering and also calls this method
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, themes, admin bar" }
Admin table list API? **wp-admin table lists - like post list** Is there a API or something to build table lists in wp-admin? With table lists I mean like the list of posts for example. It has columns, sorting, paging and so on. **Admin loop - the right way** When I create my loop I want it to look and feel like the core code, build it the right way. **No API? Give me an article** If there are no API like this, maybe point me to a great article about how to create it the best way possible.
Yes, in version 3.1 `WP_List_Table` class was introduced and admin started to move to using it. As of 3.2.x it currently is not officially declared to be stable API to be used by developers, but in practice it is usually more viable approach than building tables from scratch anyway. On admin loops - admin side is not the easiest part of WP. It might be easier to retrieve itmes how you find convenient in your class extending `WP_List_Table` then trying to replicate admin mechanics precisely.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp admin, pagination, api, columns, sort" }
New custom menu created. how to apply it? i have a childtheme from twentyeleven, i created a 'inicio' (name) custom menu, !enter image description here how can I apply it? tried: <?php wp_nav_menu( array( 'theme_location' => 'inicio' ) ); ?> but not working (not even change visible) EDIT Trying now: header.php: (child) * * * <?php //wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?> <?php wp_nav_menu( array( 'theme_location' => 'inicio' ) ); ?> functions.php (child) function register_my_menus() { register_nav_menus(array('inicio' => 'Inicio Menu')); } And still seeing 'default' navigation menu
You should have a theme locations dropdown titled inicio, select the menu you created here and it will work. Alternately, if you just want to replace the main menu, select inicio in the Theme Locations box under Primary Menu.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, menus, headers, theme twenty eleven" }
WP_Query - Order results by meta value I've checked around and haven't seen an answer which works as of yet. I have a WP_Query with the following arguments: $args = array( 'post_status' => 'publish', 'post_type' => 'listing', 'meta_key' => 'client_feedback_score', 'orderby' => 'client_feedback_score', 'order' => 'DESC' ); $query = new WP_Query($args); I want to order the results by the custom post field `client_feedback_score`, lowest to highest. But this doesn't seem to work... can anyone point me in the right direction? **EDIT (SOLVED):** Thanks to Milo's response, here's the working code for ordering by a numerical meta value: $args = array( 'post_status' => 'publish', 'post_type' => 'listing', 'meta_key' => 'client_feedback_score', 'orderby' => 'meta_value_num', 'order' => 'DESC' );
`orderby` should be `meta_value_num`, or `meta_value`, not the name of the key. See WP_Query orderby parameters.
stackexchange-wordpress
{ "answer_score": 92, "question_score": 74, "tags": "custom field, wp query, order" }
update_user_meta: How many is too many? I am working on a community portal that may in future cater to extremely large user base. All users have about 50 settings that needs to be stored to the user meta. These settings would be frequently accessed and overwritten with new values when the user saves changes to their profile. This would lead to extremely large number of calls to update_user_meta courtesy: large user base and large number of settings per user. Would these high number of calls to update_user_meta cause any performance degradation? An alternative that I see, would be to write the user settings to an array and subsequently store the array to user meta using a single call to update_user_meta. Which of the two appears to be a better solution? Regards John
To answer your questions: > Would these high number of calls to update_user_meta cause any performance degradation? The Higher the number of calls to the database the slower its going to work since every query takes some (not much but still) time. > Which of the two appears to be a better solution? Recently I finished a project with similar amount of user settings and the solution i ended up with was to store as an array all of the data that i didn't need to query or search based on, (since when using array to store data in the data base it is stored serialized ) and the rest (data that needs to by queried based on) as single rows of data, which cut down the queries on one page from 68 to just 7.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "custom field" }
Add a submenu to wp_nav_menu I literally don't know where to begin with this. The only wp_nav_menu() documentation I found was < and all submenu docs reference a different function or layout. What can I do?
Just drag and drop menu items in admin area. Submenu will automaticly appears in html. Then you can style it with css as you wish. Dropdown or something else. !enter image description here
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "menus, templates, navigation, sub menu" }
Right align a youtube video I'm trying to right align (class="alignright") a YouTube video AND allow my client to edit the surrounding text in the future using the visual editor. I simply added class="alignright" to the tag containing the embed using the HTML editor however when any changes are made to the text using the visual editor WordPress strips the extra code. I think it might be impossible to get the result that I want but could anyone confirm my suspicions or give me a workaround.
Use an id and CSS selector for the element and align it in your stylesheet.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, css, html, visual editor, youtube" }
WordPress Custom Page Template in a different directory Is it possible to have a custom page template in a different folder? I'm setting up a little framework for WordPress that I can use over and over for themes and just for the sake of being tidy I want to put custom page templates inside a different folder rather than the root of the theme directory. How would one go about this?
WordPress uses `get_page_template()` to determine the template file to use which can be altered by filters: //for pages add_filter( 'page_template', 'My_custom_page_template' ); function My_custom_page_template( $page_template ) { if ( is_page( 'my-custom-page-slug' ) ) { $page_template = 'pathto/custom-page-template.php'; } return $page_template; } //for posts add_filter( 'single_template', 'My_custom_page_template' ); function My_custom_page_template( $single_template ) { if ( is_single( 'my-custom-page-slug' ) ) { $single_template = 'pathto/custom-post-template.php'; } return $single_template; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "php" }
Uncaught SyntaxError: Unexpected Token Illegal I have a local install of Wordpress running & I am suddenly getting these errors in my console when I open a modal window (such as file upload): Uncaught SyntaxError: Unexpected token ILLEGAL media-upload.php:75Uncaught ReferenceError: jQuery is not defined media-upload.php:89Uncaught ReferenceError: SWFUpload is not defined media-upload.php:156Uncaught ReferenceError: jQuery is not defined load-scripts.php:1Uncaught SyntaxError: Unexpected token ILLEGAL Non-wordpress site's work fine and I've never had any issues like this before, it seems to be limited to Wordpress. What I don't understand is that the modal window is being called and loading AJAX content, additionally all the transitions work in the rest of the Wordpress admin area. Does anyone have any suggestions? Thanks
Ok this appears to have been solved by turning on `short open tag` and `zlib output compression` in the php settings of WAMP
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp admin, admin, errors, localhost" }
How to exit a plugin's execution mid-stream? I have a plugin that I want to ensure runs ONLY on singular posts, pages, etc. I'm using the is_singular() function and it works great - except that all it does is return execution to the rest of the plugin if I do this: function singular_check(){ if(is_singular()) return; } I'm executing it in a hook like so: add_action('wp', 'singular_check'); I need to actually make my entire plugin bail out at that point, and return to executing whatever else was downstream of my plugin. Anyone know how to do so?
A possible solution would be to hook in way late (template redirect, for example), do your conditional check. If it passes, include (or require) a file that contains the stuff needed. <?php add_action( 'template_redirect', 'wpse30291_template_redirect' ); function wpse30291_template_redirect() { if( ! is_singular() ) return; require_once( 'your-file.php' ); } This is not going to work if `your-file.php` contains functions hooked into things that happened earlier (eg. `init` or `wp`). But if `your-file.php` contains things that, say, modified content (hooking in `the_title` or `the_content`, for instance) then it would be fine.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development" }
Display SQL that wordpress is running I am wanting to see the actual SQL that worpress is running to build certain pages, is there a debug method or some other way to outpout this or view it?
You can use any one of these filters from /wp-includes/query.php posts_where_request posts_groupby_request posts_join_request posts_orderby_request posts_distinct_request posts_fields_request post_limits_request You can print certain parts of the query to the screen to see what's going on under the hood. For instance, you can add this to your functions file: add_filter('posts_where_request', 'foo_bar', 1, 10); function foo_bar($where){ print_r($where); return $where; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "database" }
Making plugin to use different table prefix cause permission problem I have multiple wordpress websites that uses the same files and database but with different table prefixes, I use a plugin "Shortcode Exec PHP" and I would like to use the same shortcodes on all the sites, but this plugin doesn't use it's own table, it used the update_option function from wp to store the data. So I tried just adding this on top of the plugin's code: $wpdb->prefix = "mainsiteprefix_"; But I get the error: > You do not have sufficient permissions to access this page. On all the admin pages of the sites that don't uses that prefix and have the plugin activated. So, how could I make the plugin to use any db prefix I want without having permission problems?
You will need to restore the database prefix after using it , with something like this global $wpdb; $previousPrefix=$wpdb->prefix; $wpdb->prefix="mainsiteprefix_"; //Database access goes here $wpdb->prefix=$previousPrefix; or you can create a new wpdb object like this: $wpdb2 = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, wp admin, wpdb, permissions" }
How do I remove the admin bar (styling) from frontend only? When logged in, the admin bar adds the following to my page `<head>` section: <style media="screen" type="text/css"> html { margin-top: 28px !important; } * html body { margin-top: 28px !important; } </style> Now, I can remove this by disabling the admin bar /* Disable the Admin Bar. */ add_filter( 'show_admin_bar', '__return_false' ); or removing it completely /* Remove admin bar */ remove_action('init', 'wp_admin_bar_init'); I would like to keep the admin bar in the admin interface and only remove the CSS from front end. I already use CSS reset where I set `margin: 0px`, but the admin-bar styling overrides this. So how can I remove the styling from front end? PS. I know I can disable the admin bar per user, but that's not what I want.
function hide_admin_bar_from_front_end(){ if (is_blog_admin()) { return true; } return false; } add_filter( 'show_admin_bar', 'hide_admin_bar_from_front_end' ); Edit: As @Walf suggested in the comments, this could be writen as: add_filter('show_admin_bar', 'is_blog_admin');
stackexchange-wordpress
{ "answer_score": 27, "question_score": 12, "tags": "admin bar" }
Change attachment filename Is there a function that allows me to change the filename of an attachment, based on the Attachment ID I have? Thanks! Dennis
This will allow you to rename an attachment as soon as its uploaded: add_action('add_attachment', 'rename_attachment'); function rename_attachment($post_ID){ $file = get_attached_file($post_ID); $path = pathinfo($file); //dirname = File Path //basename = Filename.Extension //extension = Extension //filename = Filename $newfilename = "NEW FILE NAME HERE"; $newfile = $path['dirname']."/".$newfilename.".".$path['extension']; rename($file, $newfile); update_attached_file( $post_ID, $newfile ); }
stackexchange-wordpress
{ "answer_score": 25, "question_score": 12, "tags": "attachments" }
How can I prevent Wordpress to wrap <br> into a <p> paragragraph When I create a new page and put `<br class="clear">` into the HTML view it gets rendered as <p> <br class="clear"> </p> This causes problems with the theme ` where the `<br>` is not wrapped. How can remove the wrapping?
Use shortcode instead of `<br class="clear">`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "formatting, html editor" }
WordPress Jquery Fade in, Fade out effect I'm following a tutorial. I've included the hover.js with the following code: $(function() { // OPACITY OF BUTTON SET TO 50% $(".imgopacity").css("opacity","0.5"); // ON MOUSE OVER $(".imgopacity").hover(function () { // SET OPACITY TO 100% $(this).stop().animate({ opacity: 1.0 }, "slow"); }, // ON MOUSE OUT function () { // SET OPACITY BACK TO 50% $(this).stop().animate({ opacity: 0.5 }, "slow"); }); });
Going through your source - jQuery Source \- it seeems that `noConflict()` is getting called right at the end. To fix your hover.js then would look something like this: jQuery(function($) { //Allow the use of $ namespace in this function. // OPACITY OF BUTTON SET TO 50% $(".imgopacity").css("opacity","0.5"); // ON MOUSE OVER $(".imgopacity").hover(function () { // SET OPACITY TO 100% $(this).stop().animate({ opacity: 1.0 }, "slow"); }, // ON MOUSE OUT function () { // SET OPACITY BACK TO 50% $(this).stop().animate({ opacity: 0.5 }, "slow"); }); }); Regards,
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "jquery, javascript" }
Free Wordpress Hosting with Custom Themes? Is there any place that has free hosting for wordpress and allows custom themes? I have seen a bunch that offer free hosting but none that seem to allow custom themes. I guess I should add a Little more about why I want it to be free I just want to throw up a site for a couple days to fool around with the theme get some feedback. Not a permanent hosting solution. So if this doesnt exist that is alright but I am aware of the pros and cons of free v paid hosting. It doesnt have to be a "wordpress host" either just a good place that I can setup a wordpress install in an hr and test for 3 days and tear down.
www.POWRHOST.com offers unlimited free hosting for Wordpress and other apps. Free cPanel, free scripts, free auto-install. ### Update 14.02.2012 I just learned the hard way that each 30 days of "inactivity", the Powrhost system auto-deletes your entire blog and contents. You'll get an email that your "free account" has been "cancelled" for "inactivity". You will login to your basic account, and find you can re-activate the extra free accounts they deleted, but you have to start all over, re-instal wordpress, re-upload your theme, ec. NB - URGENT for you to always DOWNLOAD a backup of each blog's contents after each time you work on it, and keep your THEME handy, so you can restore most of it in a crisis.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "hosting, hosting recommendation" }
Remove Comments Metabox but still allow comments I already know how to remove a metabox from my custom post type edit page. However I want to remove the comments metabox but still allow commenting for the post. Because I notice when I do remove it, it disables comments. Any function I can use?
Don't remove this via CSS. The _POST part is also active and WP save the data! Use the hooks to remove meta boxes; code by scratch. function fb_remove_comments_meta_boxes() { remove_meta_box( 'commentstatusdiv', 'post', 'normal' ); remove_meta_box( 'commentstatusdiv', 'page', 'normal' ); // remove trackbacks remove_meta_box( 'trackbacksdiv', 'post', 'normal' ); remove_meta_box( 'trackbacksdiv', 'page', 'normal' ); } add_action( 'admin_init', 'fb_remove_comments_meta_boxes' ); see more on a plugin to remove all UI-elements and function for comments: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 5, "tags": "functions, comments" }
Echo class depending on Parent category What im trying to do is echo a class depending on witch of 3 Main "Parent" Categories the content was posted in , here is my code so far <article class="post <?php if ( in_category( 'dream-it' )){ echo 'dreamit'; } if ( in_category( 'build-it' )){ echo 'buildit'; } if ( in_category( 'get-the-hell-out' )){ echo 'getout'; } ?> "> I know im doing this wrong any help would be amazing ! thank you!
you probably need to get the parent category of each of the post's categories first. <?php $parent_cat = array(); $post_cats = get_the_category($post->ID); foreach( $post_cats as $post_cat ) { if( $post_cat->parent ) $parent_cat[] = get_category( $post_cat->parent )->slug; } ?> <article class="post <?php if ( in_array( 'dream-it', $parent_cat ) ) { echo ' dreamit'; } if ( in_array( 'build-it', $parent_cat ) ) { echo ' buildit'; } if ( in_array( 'get-the-hell-out', $parent_cat ) ) { echo ' getout'; } ?> ">
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories" }
shortcodes between square and curly brackets I'm having difficulty searching for the answer to this question since {} and [] don't seem to affect search queries. My question is simple: how are these syntaxes different in meaning? {short_code}{/short_code} [short_code][/short_code]
To WordPress, as it parses through the content, only the tags using square brackets will be treated as short codes. The curly bracket example given would not be parsed by the WordPress core. It is possible the tag would be parsed by a plugin or theme if they are looking for hooks in the content that they don't want handled by the core functions for some reason.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "shortcode" }
wp_list_page with something like showpost I'm using this code <?php $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0'); $subpages = ($post->post_parent) ? wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0') : wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0') ; if ($children) { ?> <li><?php echo $children; ?></li> <?php } else { ?> <?php echo $subpages; ?> <?php } ?> This code display child pages on a parent page, also if there are not childs it will display the child of the parent (brothers). However I need to restrict it to display only 5 pages, something like showpost=5 for post, I havent been able to do it, any help???
Just pass `number=5` and it should work since `wp_list_pages()` uses `get_pages()` which has number parameter, and also if you look at wp_list_pages codex entry at the bottom under change log you can see that it take the `number` parameter since version 2.8
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "wp list pages" }
When to use is_home() vs is_front_page()? I've found that `is_front_page` appears to return true when I'm viewing the home page and have a single sticky post assigned there. It also returns true when I've assigned a page as the static front page via _Settings > Reading_. Why would I ever want to use `is_home()`?
`is_front_page()` returns true if the user is on the page or page of posts that is set to the front page on _Settings->Reading->Your homepage_ displays So if you set `about us` as the front page then this conditional will only be true if showing the _about us_ page. `is_home()` return true when on the posts list page, This is usually the page that shows the latest 10 posts. If the settings under _Your homepage displays_ are left at default then the home page will return true for both `is_front_page()` and `is_home()` An example of using `is_home()`: * You have set your posts page to a page called _News_. * A user navigates there and in the header you want to show additional navigation * You could use `is_home()` to do this.
stackexchange-wordpress
{ "answer_score": 78, "question_score": 76, "tags": "theme development, homepage, frontpage, customization" }
How to get the original post_id of a static home page? I can't figure out how to get the original post_id of a specific page if that page has been set as the static posts page of the blog. I have a page that normally has a post_id of 95, but as soon as I set it to the static posts page, it returns a post_id of 0 and it's causing me lots of headaches. How can I retrieve the original post_id - which _is_ stored in the DB because it comes right back if I make it not the static posts page any longer.
the id of the posts page is: $posts_page_id = get_option( 'page_for_posts' ); the conditional tag for the posts page would be: `is_home()` edit: the id of the static front page is: $front_page_id = get_option( 'page_on_front' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "homepage" }
Is there a way to parse shortcodes in PHP? Many plugins don't provide a documented way to access their functions from within PHP (e.g. when building a custom theme), but only shortcodes to insert in posts. Is there a standard way of executing shortcode from within PHP as if it were part of the content? Like so (this is made up): $gallery_html = execute_shortcode("{gallery}"); // this would return the HTML // that the gallery plugin returns // in the context of the current post
You can execute shortcodes using the do_shortcode() function $gallery_html = do_shortcode('[gallery]');
stackexchange-wordpress
{ "answer_score": 8, "question_score": 5, "tags": "php, shortcode, templates" }
Removing all classes from nav_menu except current-menu-item and current-menu-parent Thanks to Rarst's clever answer, I'm succesfully using these bits to remove the classes from the custom menu markup... add_filter('nav_menu_css_class', 'discard_menu_classes', 10, 2); function discard_menu_classes($classes, $item) { return (array)get_post_meta( $item->ID, '_menu_item_classes', true ); } However, I do need the current-menu-item and current-menu-parent classes when I'm viewing a current page element or a child of a current-menu-item. Is it possible to add these without all the extra classes?
Sure, you can filter out all the classes but the ones you want. add_filter('nav_menu_css_class', 'discard_menu_classes', 10, 2); function discard_menu_classes($classes, $item) { $classes = array_filter( $classes, create_function( '$class', 'return in_array( $class, array( "current-menu-item", "current-menu-parent" ) );' ) ); return array_merge( $classes, (array)get_post_meta( $item->ID, '_menu_item_classes', true ) ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "theme development" }
File Attachment display title in template I've got a custom post type with a file upload field. In my template file i'm using this to display a link to that file. <a href="<?php the_field('downloads'); ?>">Download PDF</a> What i want is to be able to have it display the file title. So instead of Download PDF it will say the files title. What php would go inside the code i'm using? Thanks EDIT: Here's the code that i put in the comment below. I'm guessing this is what you were asking for. I looked through the files for the plugin i've used and found this function. function the_field($field_name, $post_id = false) { $value = get_field($field_name, $post_id); if(is_array($value)) { $value = @implode(', ',$value); } echo $value; } Please let me know if this isn't what you meant or you need to know anything else.
I've used a work around for this. Instead of using the title name for the file i've added another field to use as the title. Not the way i intended but it works.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "attachments" }
Query Posts Creates 404 Error When I'm on archives pages I am using the code below to query posts. In my theme options to_count_home calls the number of posts. WordPress isn't generating the correct number of pages based on posts_per_page. Instead it is generating pages based on the number of posts per page I have selected in my default WordPress settings. For example, if I have 10 posts per page in the settings then set posts_per_page in the code as 5, when I go to the second page (which should have 5 posts on it) I get a 404 error. Here is the code I'm using: <?php $per_page = get_option('to_count_home'); query_posts("posts_per_page={$per_page}"); if (have_posts()) ?>
You are not modifying your query, but nuking it completely. Please see `query_posts()` documentation in Codex on how to correctly re-run query with changed arguments.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query posts, archives" }
A way to detect which page a post is on I'm wondering if there is a good way to tell which archive page a post came from. I essentially just need the post's position in the total order, then divide it by the 'posts_per_page' option. The hangup I'm having is getting that position or offset of where the post sits. EDIT: All while being on the SINGLE POST template. There, no matter what, the usual $wp_query global and 'page'/'paged' query vars are always 0 - so those won't get me anywhere.
Alright, nevermind. I got this solved by doing this at the top of the single post template: $position_query = array( 'post_type' => 'portfolio', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => -1 ); $position_posts = get_posts($position_query); $count = 0; foreach ($position_posts as $position_post) { $count++; if ($position_post->ID == $current_id) { $position = $count; break; } } $posts_per_page = get_option('posts_per_page'); $result = $position/$posts_per_page; $current_page = ceil($result);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "posts, pagination" }
Create New Admin Menu Section - Like how custom post type works, in a way I've been working with Wordpress off and on for years now, but I haven't gotten entirely immersed with the framework. I have no problem creating plugins that use custom post types, but I'm looking to add a new section in the admin that isn't for posts, but rather my own custom tables. I know how to create the custom tables on installation of the plugin, I'm just looking for the right information to create a new menu section with subsections, but I'm having a hard time finding the answer. What functions/hooks do I need? I'll figure out the rest after that.
Check out the Administration Menus section in the Codex, I actually used it pretty heavily over the last couple days to create a sub-menu and it helped a lot. It goes into detail on the top level menus as well. You'll specifically need the add_menu_page() function to create the top level menu, as well as the add_submenu_page() function to create the sub menus. From there it's just a matter of meticulously adding options and setting fields. Also of great help in understanding the flow of things was Otto's WordPress Settings API Tutorial.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development, database" }
How to get Wordpress to NOT alter the permalink structure when adding a static page? This is driving me nuts and I'm hoping someone knows of a way around it. Say I have a permalink structure of `/%postname%/` and I have URLs like `www.domain.com/blog/post-name/`. So I go about linking and what have you out in the big bad internet. But, now I decide I want to add a static home page. Say it's a page called "my page". Suddenly WP changes ALL my permalinks to look like `www.domain.com/blog/my-page/post-name/`! So all the links I have created now point to the wrong place, and my plugin which does some things by retrieving the `post_id` of the requested url, utterly breaks because that page no longer exists. Why on earth the WP team would think this is a great idea is beyond me, I simply want to set a specific page to appear when someone visits the root of my blog, not insert that page into the path of all my links. How can I disable this "feature" or otherwise work around it?
It sounds like user error to me, or possibly a plug-in. I am leaning towards operator error. WordPress just gives you the vehicle, your the one at the wheel. The good thing about WordPress is it allows people without the knowledge it takes to build a website a chance to jump right in, sink or swim. It's all a matter of how you set it up. You should always plan ahead and think about how your site will be set up in relation to "Front Page", "Posts" or Blog, categories etc... If you changed your site from front page displays: a Static Page, then switched it, you might have some "hard-coded" links that are not re-directing. Have you tried visiting the Permalinks page and clicking the update button to see if it fixes it?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks" }
How to retrieve the post_id of a tag page? Thought this would be straight forward... given a tag page such as ` how can I retrieve the `post_id` while on that page? The usual suspects such as `url_to_postid` and `$post->ID` or `$wp_query->post->ID` do not return anything. The hook that calls the function is running during `init`. Thanks!
A tag page would be like other archive pages in that a loop of posts would be displayed, even if only one post has been assigned that tag. You're check for post ID needs to happen during the `<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>` loop.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "tags" }
How do I make images appear in the beside blog post summaries? I don't know if this is a WordPress question or a CSS question... On my blog, in the list of post summaries, an image from a post appears beside the post's summary in the list of posts. But that only happens with one post. Other posts have images, but no thumbnail image appears in the list of post summaries. I want to make it so that whenever I include an image or a video in a blog post, in the summary list, a thumbnail of the image appears. If I include more than one image in a blog post, then just one thumbnail appearing is ok. Ideally, clicking the image would click into the blog post. You can see the list of summaries at < The one thumbnail is 11 posts from the top. Thanks,
It's hard to tell without seeing the theme files but I assume the one image is displaying because it is set as the "Post Thumbnail" or "Featured Image" on that particular post and that all other posts aren't using that feature. The easy solution in that case would be to make sure you set any images you use in the post as the "Featured Image" as well. If that isn't the case then you can modify your themes function file to grab the first image of any post and then modify your index.php file to include that image if it exists. Here is a good tutorial on that: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post thumbnails" }
Query posts by custom taxonomy ID I have a custom post type called `portfolio` and a custom taxonomy called `build-type` (acting as categories) I am trying to query `portfolio` posts by `build-type` ID e.g. all Portfolio posts in "Hotels" (id=4 for that taxonomy) // gets the ID from a custom field to show posts on a specific page $buildType = get_post_meta($post->ID, 'build_type_id', true); // run query query_posts(array( 'post_type' => 'portfolio', 'showposts' => -1, 'tax_query' => array( 'taxonomy' => 'build-type', 'terms' => $buildType, 'field' => 'term_id' ), 'orderby' => 'title', 'order' => 'ASC' )); Currently it's calling **all** `portfolio` posts and not just those with the `build-type` ID For `'field' => 'term_id'` should I be using `term_id`, `tag_ID`, `id` or something else? Anyone know how to get this working? Thanks in advance!
The reason this isn't working is because 'tax_query' needs to be an array of arrays (confusing, I know). ... 'tax_query' => array( array( 'taxonomy' => 'build-type', ... It is that way so you can group a few different rules together.
stackexchange-wordpress
{ "answer_score": 14, "question_score": 8, "tags": "query posts, tax query" }
wp_login_form: Redirect to dynamic url according to username i need to redirect users after login. I use `wp_login_form` to provide a login form on the frontpage. After a user entered username and password i'd like to redirect to a custom url, like < where 'username' is the name the user entered. Could i somehow filter `login_redirect`? Thank you!
You can filter and set where you want to redirect to which user or role with the plugin Peter's Login Redirect.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "redirect, login" }
Upload files into buddypress profiles Someone knows any plugin or method to allow users to upload files into their profiles? I mean i can link those files later to their profiles is the files are linked to users some way. I want to allow my users to upload papers, pdf , etc and then show those files on their profiles. Thanks in advance!!
I found this great plugin called "Uploadify Integration" by Mike Allen that did the trick.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 2, "tags": "buddypress" }
WordPress Meta Title Separator This code, when used in the header, automatically adds a arrow to wp_title. How do I remove this? <title><?php bloginfo('name'); ?><?php wp_title(); ?></title>
Check out the documentation for wp_title(), as there are several things you can do to format it how you want. Using the following code will remove the double arrows in the title: <title><?php bloginfo('name'); ?> <?php wp_title("",true); ?></title>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "seo, headers" }
How can I default a new post to being saved? I'm trying to figure out how to make it so that as soon as the post-new.php page for a custom post type is loaded, the post is saved. Basically, I'm trying to make sure the post has it's postID saved before anyone even starts entering anything. I suppose I could probably "fake-click" the "Save Draft" button, but I'm wondering if there's a more legit way to handle it.
This should work. It's the way press-this gets the post id when you click the bookbarklet. add_action( 'load-post-new.php', 'prefix_save_it' ); function prefix_save_it() { // define some basic variables $quick = array(); $quick['post_status'] = 'draft'; // set as draft first $quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null; $quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : null; $quick['post_title'] = isset($_POST['post_title'] ? $_POST['title'] : null; $quick['post_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : null; // insert the post with nothing in it, to get an ID $post_ID = wp_insert_post($quick, true); if ( is_wp_error($post_ID) ) wp_die($post_ID); $quick['ID'] = $post_ID; wp_update_post($quick); } return $post_ID; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, custom post types" }
Change Twentyeleven Search Form Text Anyone know how to change the text inside the Twentyeleven search field from "Search" to another choice?
Open `searchform.php` Find this in line 12 and edit Search as you wish placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>"
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "search, theme twenty eleven" }
How to determine if it is legal to remove credit link from theme? I have downloaded a theme and modified few things and customised it according to my needs. Now I want to remove the credits i.e. the back link to the designers site. I want to know if its legal for me to remove that. What are the terms and conditions? Theme is < Credits is a backlink: Theme by Niyaz Diovo (with link)
Theme licensing information is typically included in `style.css`. According to that Voidy theme is at least partially under GPL license (version not specified): > The CSS, XHTML and design is released under GPL There is no issue with removing front-end credits/link from GPL-licensed theme.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "theme development" }
trying to Change to wp_register_sidebar_widget I got this in my theme: register_sidebar_widget(array('Sidebar Login', 'widgets'), 'widget_sidebarLogin'); i want to change this to the updated Command aka wp_register_sidebar_widget But i seem to miss something cuz the widget doesent load after the change.. I tried this: wp_register_sidebar_widget( 'SidebarLoginId', // your unique widget id 'Sidebar Login', // widget name 'widget_sidebarLogin', // callback function array( // options 'description' => 'Some description' ) What am i missing? is that "widgets" in the original 'register_sidebar_widget' array has a meaning othere then description ?
function widget_sidebarLogin() { echo "Content of Your Widget"; } wp_register_sidebar_widget( 'sidebarLoginId', // your unique widget id 'SidebarLogin', // widget name 'widget_sidebarLogin', // callback function array( // options 'description' => 'Some Descriptions' ) );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "widgets, user registration" }
How to make an image of a YouTube video appear as a thumbnail in the list of blog posts How do I post a YouTube video so that an image of the video also appears as a thumbnail in the list of posts. Here's the blog in case that helps: <
> MayBe This Plugin can help you out : < > But if you want to do this manually then you can get Video Image from this Link : < Replace "SgGVitTU9F8" to your video id
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "youtube" }
How to post images on my blog with a pre-defined border The images in this blog post: < ...have borders around them -- hatched lines. But in this post: < there's no border around the image. The images in the first example above I think I posted using the 'From url' function. In the second example listed, I used the 'upload' function when posting the image. Is there a way of posting images using the 'upload' function so that the border appears?
this is more a css problem than wordpress related - check style.css of your theme: the 'border' (actually a padding with background image) is only set for left, right, and center aligned images (like those from your first link), not for those with .alignnone (those from your second link): #content img.alignleft, #content img.alignright, #content img.aligncenter { background:url("images/wf-hashes-wht.gif") repeat scroll center center transparent; margin-bottom:12px; padding:6px; } if you want the same behaviour for non-aligned images, add `#content img.alignnone` to the above list (don't forget to add the comma)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images" }
Adding thumbnails independent of images in blog posts Is it possible to add thumbnails to blog post listings independent of images in a blog post -- e.g. if there is no image in the blog post, can I add a thumbnail image?
> Is it possible to add thumbnails to blog post listings independent of images in a blog post set the 'featured image' when writing/editing your post; and use `the_post_thumbnail()` within the loop, in the template. > e.g. if there is no image in the blog post, can I add a thumbnail image? dependent on a post image, you can check (in your template, in the loop) if the post contains an image, and then output the post thumbnail, for instance with: if( !strpos(' '.$post->post_content, '<img ') ) the_post_thumbnail(); details depend on your design.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails" }
How to keep plugin translations after updates? bbPress' language folder (`wp-content/plugins/bbpress/bbp-languages`) has that warning: /** * Do not put custom translations here. They will be deleted on bbPress updates. * * Keep custom bbPress translations in /wp-content/languages/ */ Actually, this is not a new problem and yes, they are right. This is a big problem if you are using WordPress plugins with a non-English language. Basically, I translated bbPress and created `.po` and `.mo` files. Files are working if I put them in their normal `wp-content/plugins/bbpress/bbp-languages` folder. But as the above warning says, they will delete on update. But the problem is translations are not working if I put them in the `wp-content/languages/` folder as suggested in bbPress. I think there must be a hook or something I can activate it but what is the best solution for it? Simply I want to keep plugin language files in `wp-content/languages/`.
You have to replace the call to BBpress’ language file. A good place to do this is a language specific file in your general languages directory. For Turkish it would probably be a file named `tr_TR.php`. This will be loaded automatically and _only_ if it matches the language of your blog. It will not be overwritten. BBPress doesn’t use the function `load_plugin_textdomain`, it uses `load_textdomain` instead. Here you can find a filter: $mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain ); So in your language php file just add a filter to change the path: function load_bbpress_tr_mofile( $mofile, $domain ) { if ( 'bbpress' == $domain ) { // replace this. :) return 'FULL_PATH_TO_YOUR_FILE'; } return $mofile; } add_filter( 'load_textdomain_mofile', 'load_bbpress_tr_mofile', 10, 2 );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 9, "tags": "plugins, multi language, bbpress, language" }
How do I call posts with a certain tag? I use this to call posts: <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $per_page = get_option('to_count_archives'); query_posts("posts_per_page=".$per_page."&paged=".$paged."&cat=".$cat); if (have_posts()) ?> <?php while (have_posts()) : the_post(); ?> And it works great for categories. But **on archives pages generated for tags it shows ALL posts, not just posts with a specific tag**. I am going to creates a separate archives.php and category.php. I need to keep the to_count_archives part of the code because it calls the number of posts per page. I appreciate any help rewriting the code above to work correctly.
It's because when you call `query_posts`, you're overwriting the original query with a new one, you have to get the original query and reset the things you want to change. global $query_string; $per_page = get_option( 'to_count_archives' ); query_posts( $query_string . '&posts_per_page=' . $per_page );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, query posts, archives" }
Loop custom post type by taxonomy (Category) I created a custom post type in my function.php of the theme and some a taxonomy for them. I added 2 categories in my taxonomy (first, second) and added some post in my new custom post. I want to make a loop that will select from my custom posts only the ones in the first category (Taxonomy) Or I want a archive that will display all my custom posts, but separated by the taxonomy like First category: one post, another post Second Category: this post, next post
Before the loop starts use query_posts. Available parameters are here. Something like this: global $wp_query; query_posts( array( 'post_type' => 'mycustomname', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'mytaxonomyname', 'field' => 'slug', 'terms' => array( 'myterm1slug', 'myterm2slug' ) ) ) ) );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, taxonomy, loop" }
Find out if enqueued script uses wp_localize_script? Is there a function that can check if an enqueued script has a call to wp_localize_script attached to it?
Try this: function is_localized($tag) { global $wp_scripts; $data = $wp_scripts->get_data( $tag, 'data' ); return ! empty( $data ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp localize script" }
How to show content for posts of a specific category only I show excerpts of all posts at this site. Which works fine. However, I would like show content for posts of a specific category, while keeping all others showing excerpts. Is it possible, without a plugin? With a filter in functions.php, etc.? Working with 3.1.4, twentyten.
You can use the `in_category` function to test if the current post in the loop is in the specific category you want to display full content for. For example if ( in_category( 'my_category') ) : the_content(); else : the_excerpt(); endif; For more information on the `in_category` function see the WordPress codex at: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "content, excerpt" }
Dequeue script, but still use wp_localize_script to pass vars I need to dequeue some scripts but still have access to the vars passed via their wp_localize_script calls. Is there a way to do that?
I don't think so, since localize output is tied to script's print event. You will probably have to access that data and output it in some other way.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "plugin development" }
Which is the child theme and which is the parent theme? In the themes folder for my blog, there are three folders and one file: The file is index.php and the folders are: twentyeleven / wordfruit / twentyten The blog is at < Obviously folders could be given any label, but I think the folders are organised fairly logically. Question 1: Is 'twentyeleven' likely the child theme and 'wordfruit' likely the parent theme? Question 2: I want to edit a file so that when a user clicks a thumbnail image in the list of blog posts, the blog post opens up... (As per this post: How to make thumbnail images click into blog posts ) As I understand, I need to edit the index.php file... Do I edit the index.php in the child theme or the parent theme?
Your site is not using a Child Theme. It is currently using the **WordFruit** Theme, and this Theme **does not declare any Theme as a _Template_**. If it _were_ , you would see a **`Template: parent-theme`** header tag (where "parent-theme" would be, e.g. `twentyeleven` if it were using Twenty Eleven as its parent Theme) in style.css Thus, WordFruit appears to be a **stand-alone** Theme. So, if you want to make changes to WordFruit, you would need to make changes to the Theme directly, or create a Child Theme that uses Wordfruit as its template (Parent Theme).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "child theme, parent theme" }
Fatal error: Call to undefined function wp_create_nonce() I'm trying to add a nonce to my plugin's Ajax. I'm not sure why I'm getting this error: > Fatal error: Call to undefined function wp_create_nonce() In my php file : wp_localize_script('my-ajax-handle', 'the_ajax_script', array('ajaxurl'=> admin_url('admin-ajax.php'), 'my_nonce' => wp_create_nonce('myajax-nonce'))); In js file: jQuery.post(the_ajax_script.ajaxurl, {my_nonce : the_ajax_script.my_nonce}, jQuery("#theForm").serialize() + "&maxLat="+ map_bounds[0] + "&maxLong="+ map_bounds[1] + "&minLat="+ map_bounds[2] + "&minLong="+ map_bounds[3], function(response_from_the_action_function){ jQuery("#response_area").html(response_from_the_action_function); }); Any suggestions on how to solve this? Thank you.
More context would be helpful. Is that all the code found in your plugin or functions file directly? Or are you hooking in to something via `add_action`. Anyway, what's probably wrong is that you're calling `wp_localize_script` and `wp_enqueue_script` outside of an action. `wp_create_nonce`, or, rather, the file in which it resides, has yet to be loaded. The solution is to call `wp_localize_script` from inside a function hooked into `wp_enqueue_scripts` <?php add_action( 'wp_enqueue_scripts', 'wpse30583_enqueue' ); function wpse30583_enqueue() { // your enqueue will probably look different. wp_enqueue_script( 'wpse30583_script' ); // Localize the script $data = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'wpse30583_nonce' ) ); wp_localize_script( 'wpse30583_script', 'wpse3058_object', $data ); }
stackexchange-wordpress
{ "answer_score": 8, "question_score": 3, "tags": "nonce" }
Thumbnail Image Rounded Corners w CSS (or any other good method) I've been researching how to display thumbnails with rounded images, but every solution ends up running out of gas. One trick I tried was wrapping the thumbnail in a division with the same size and shape, showing the image, but with CSS of `opacity:0` so that the actual image doesn't show. What shows is the background image for the division, and it's this, also that is styled using: `border-radius: 15px;` (plus other browser related hacks) To do this on WordPress, I'm going to have to use inline styles, it seems, to give the same div the right background image using the_post-thumbnail() Seems to lead to nowhere because I don't see a way to pull just the image url in a way that I can call within <div style=" "; Any ideas? I'm trying to avoid Javascript, but if that's the only way... Here's a link to the method I mentioned
You can get the thumbnail URL with wp_get_attachment_image_src and get_post_thumbnail_id: $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); echo $src[0];
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, images, css, post thumbnails" }
How to display an RSS feed widget inside a page? I have an RSS feed (link) that I would like to display as a widget inside one of my posts. The wordpress RSS widget already does that on the sidebar, is there some solution to have it in the post? The best solution would latter let me do something like: So I could embed this also on other sites. Thanks.
if you know php you could add it to a template using wp function < or there is wp code to pull in a feed and list it < if you want a non coding solution, there are some plugins like: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "widgets, rss, embed" }
CSS/JS files in WordPress In web development, I get used to place css/js files under separate folders (css folder, js folder ..etc). What I am experiencing in WordPress is that I cannot access these folders in WordPress Admin Editor Page, the editor only displays the files under the main theme folder, not the nested folders. Is there an option to enable showing nested folders? is there a plugin to accomplish that? If not, then what is the best practice to follow for placing files and folders under WordPress folder?
The theme editor is located under _/wp-admin/theme-editor.php_ and uses `get_current_theme();` to give you the first files to edit. From the returned `array` of theme data, it uses `'Template Dir'` to locate the directory and `'Template Files'` to give you a list of files to edit (loops through the files with a `foreach` loop). For stylesheets it uses `'Stylesheet Dir'` and `'Stylesheet Files'` to loop through. Point is that: **1.** there are no filters or hooks, so you'd need to modify core directly (which is not recommended, as your changes would be overwritten on update) and **2.** you'd need to write a function that reads the whole folder, finds all subfolders and then another one to find all containing files and last loop through them too.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, css, javascript" }
Is there any global functions.php file which works for any theme? Is there some global kind of functions.php file that works for any theme? The problem is here: When I change a functions.php file in any theme, I need to take care of two changes: First, I need to take care of the updates of that theme. Second, I need to take care of changing the theme of the site. So, instead of making changes in the functions.php of a theme, is it possible to make changes in some functions.php file that is independent of any theme?
The difference between theme and non-theme code is organizational rather than technical. Any code that is active contributes to resulting environment, does not matter where it is loaded from. There is number of places where code gets loaded from, which are not part of WordPress core: * `wp-config.php` configuration file * active theme (and its parent in for child themes) * active plugins * must use plugins * drop-ins (these are somewhat advanced and serve very specific purposes) Typical place for your own code, that should not be part of theme, is to create a plugin. Other approaches do not have benefits from generic case, but forfeit interface (managing through admin area) and technical (activation/deactivation/uninstall events) conveniences of normal plugin.
stackexchange-wordpress
{ "answer_score": 15, "question_score": 11, "tags": "functions, themes" }
Add New Post (Custom Post Type) Deletes 1 Post's Custom Meta Data function save_details( $post_id ){ if ( wp_is_post_revision( $post_id ) ) $post_id = wp_is_post_revision( $post_id ); update_post_meta( $post_id, "testimonyname", $_POST["testimonyname"] ); } add_action('save_post', 'save_details', 10, 1); I have a custom post type with a custom field, but after adding several i noticed that the data in the custom field was missing from some previous entries. I filled them in again and it looked fine. Then i clicked the Add New button just once and 1 of my posts has it's custom meta data deleted. However, it doesn't happen every time i click Add New. I have tried this solution but to no avail if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) Any help would be much appreciated, Thanks, Ashley
if(isset($_POST["testimonyname"])) Placing this code before the update_post_meta lines worked perfectly.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, custom field" }
Is it possible to tell if a user is logged into Wordpress from looking at the cookies which are set? Is it possible to tell if a user is logged into Wordpress from looking at the cookies which are set on a site? If not, how could I add hooks to the login success and logout actions and set my own cookies?
You could use Javascript <script type="text/javascript"> function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } var logged_in=getCookie("wordpress_logged_in_[HASH]"); if (logged_in!=null && logged_in!="") { alert("You are logged in!"); } else { alert("You are logged out!"); } </script> NOTE: Wordpress logged in cookie info can be found here. You'll need to figure out what your hash is and possibly use regex for the hash. (this is untested but should work) JS cookie source
stackexchange-wordpress
{ "answer_score": 1, "question_score": -2, "tags": "wp admin, admin, users, user access, cookies" }
Why does hitting enter in Visual Editor add <p> instead of <br>? Why does hitting the enter key in Visual Editor add `<p>` instead of `<br>`? What I want sometimes is a new line that starts immediately after the previous line. Unfortunately, the visual editor automatically wraps my new line in a `<p>` tag when all I really want is a `<br>` tag so that there is no space between the two lines. How can I solve this without specifically changing my code in the HTML tab?
Hit `Shift + Enter` and you''ll get `<br>`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "html, visual editor" }
What is the current page's Taxonomy? I need to be able to switch between the current page taxonomy so I can load in the appropriate menu: $current_tax = 'need to get this from somewhere'; switch ($current_tax) { case 'tax1': // load menu1 break; case 'tax3': // load menu2 default: break; } I'm not sure which method is best to get the current page's taxonomy.
Just replace tax_name with the desired taxonomie $tax = wp_get_post_terms($post->ID, 'tax_name'); echo $tax[0]->slug;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, taxonomy, menus, pages" }
Custom Post Type - Upload Form So Im just getting started with Custom Post Types. I'm trying to make a custom post called a Certificate. The thing is, I don't need any of the usual 'editor' boxes or anything that would normally be in a post. All I need is an upload form for a user to upload a file. So I've set up the the Certificate post-type, and I made it so it doesn't support anything, so nothing appears on the page. I then added a 'admin_init' hook to display a form. But now i'm a little stuck. Can someone give me a breif outline of what hooks to use to process the form? How do I make it so it activates this hook only for 'Certificate' post types?
Take a look at this answer.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types" }
Menus, but not by theme location I'm trying to figure out how to display a menu that has been created, but without having to assign the menu to a theme location. From what I can tell, you have to assign a menu to a theme menu location and then `wp_nav_menu calls` a menu from whatever location you want. I don't want to have to assign a menu to a theme location. Instead, I want to be able to create a menu and then query it within my theme... regardless of theme location. I've created a plugin for myself that uses `wp_get_nav_menus` to list all of the menus I've created... I can then assign any menu to a page/post. Now, I'm stuck trying to figure out how to retrieve that specific menu... again, not menu theme location. Anyone?
`wp_nav_menu` takes an optional argument called `menu`, which will fetch any menu by name, slug or ID. If you just want post objects (or anything but the menu HTML), `wp_get_nav_menus` is the way to go. Otherwise, use `wp_nav_menu`. If you need it to return the menu HTML instead of echoing, there's an argument for that as well: `echo`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, theme development, menus" }
Repeatable configuration package It's normal that a developer or a shop will spend several hours on each project running the same configuration options (for permalinks, SEO options, user roles, plugins that you always use etc.). I'm coming from Drupal, where installation profiles have allowed me to preconfigure a set of configuration options that I can replicate across dozens of sites. This has saved me and my clients hundreds of hours. I now have an opportunity to do the same in WordPress. I'd like to create a script that installs WordPress, installs some plugins and sets some initial configuration options. This has the potential for useful time/cost savings when scaled across many sites. Is this feasible? Or am I barking up the wrong tree?
Not exactly what you are asking for, but very close. There is a concept of 'dropin' plugins that exists primarily to override or add to core functions The dropins will always load. So one ftp's up wordpress including whatever plugin files you want that will create your default environment. These should be in the top level wp_content folder. I have one called **install.php** which overwrites the pluggable function wp_install_defaults with my own set of defaults (starting pages, default widgets, categories, taxonomies etc etc. ) It could load starting options for other plugins as well and possibly activate them. Then you click the famous 5 min install (the 'script' you mention). It installs wordpress and applies your custom options from the dropin plugin. some brief information here: <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "installation, automation, configuration" }
Is the bulk_action hook stable for use in 3.2.X? Working on a plugin for wp-ecommerce publish / unpublish all items in a category seems the cleanest place to implement this is in the categories page as a bulk action - though numerous google searches have turned up very little documentation and a series of posts on bug tracker so: Is it now safe to add a bulk_action-ID hook or should I make a custom sub-page in the admin? Thank you in advance
Long story short the answer is NO There is no function currently available to add bulk_actions only remove them
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, bulk" }
How to make user inactive by default while registering? When user registers to my site I want to make them inactive by default so I can manually update their status and send them their login info. I am using wordpress 3.1.2. Is it possible? Are there any plugins for this? BTW, I am using Cimy User Extra Field plugin to add more fields to the registration page.
/* Plugin Name: Role-less New Users Description: Removes all roles from new registrations. Author: 5ubliminal */ // Hook into the registration process add_action('user_register', function($user_id){ $user = new WP_User($user_id); // Remove all user roles after registration foreach($user->roles as $role){ $user->remove_role($role); } }, 11); Create a new _.php_ file. Paste the code above in it. Put it in your _/wp-content/plugins_ folder and activate it. **Do test it!** **PS** : _Be advised, PHP 5.3 syntax, closures used. Incompatible with PHP 5.2 or older._
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "user access" }
Category Archives: Show posts categorized in parent category only When I view a category page in 2010 theme, it shown posts categorized in: 1. the category visible in url 2. child categories of 1. I want to restrict the results to 1. only. Please help.
And this is the _indirect_ way I am using now. If there is any better answer please do share. while ( have_posts() ) { the_post(); $cat = get_query_var('cat'); $categories = wp_get_post_categories(get_the_ID()); if (in_array($cat, $categories)) { ... } } // end loop
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, theme development, archives, theme twenty ten" }
Best Query for blog posts I am not getting any headway in this one problem I have a separate homepage from the normal blog page. However the site needs a blog so How do I structure a query that will display something like the default wordpress behavior
Do the following: 1. Create a blank page with the name "Blog" or "News" or whatever you like to call it. 2. Go to **Settings -> Reading** and select **A static page** from _Front page displays_ section. 3. Choose your front-page from the **Front page** dropdown box, and your blog page (the page you created in step 1) from **Posts page** dropdown box. 4. Save your changes. Your blog page should now display your posts when visited.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "query posts, query" }
Wordpress Dashboard Incoming Links Error Hy all! I have a problem with the Wordpress Dashboard - the Incoming Links are not working. I only get "A feed could not be found at I have tried a few solution but nothing works for me. Here is the link, that I have added: " Greetings!
1. Click configure and copy the URL (in your case, it sounds like it is: 2. Paste the URL into your browser, and you'll notice that it redirects you to 3. Copy the URL that it redirects to in Step 2, and paste that into the textbox that appears when you click Configure. 4. Save your changes, and the widget should populate correctly.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -3, "tags": "rss, dashboard" }
How to make custom fields respect paragraph breaks In one part of my site I am displaying custom field data like this: <?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'info', true); ?> This works ok but it strips any paragraph breaks out and displays it all as one big block which makes it hard to read. So how do I make it respect the paragraph breaks? many thanks in advance! James
this obviously depends on the content of your 'info' custom field; generally, you could try: echo apply_filters('the_content', get_post_meta($postid, 'info', true));
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "custom field" }
WordPress: Create A Widget to Accompany Plugin So I have a plugin that I've created for the admin are when creating post... and I'd like to supply a widget along with it. I'm trying to figure out the best way to initialize my widget. I'm initializing my plugin like so: function call_menu_per_page_class() { return new MenuPerPage(); } if ( is_admin() ) add_action( 'admin_menu', 'call_my_class' ); Obviously, the widget does NOT require someone to be an admin to view it... it will be viewed in a sidebar within my Theme. Is there a specific action/filter and hook that I should use to execute my widget class? Remember, this is being packed with my plugin... so it can't be called from `functions.php`
According to Codex `register_widget()` should be hooked to `widgets_init`. Hook into `init` then and at that point hook further different methods to appropriate hooks later.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, plugins" }
Setting up wordpress on a hosting server for the first time I'm moving a wordpress CMS installation from one host to another. Pretty straightforward I think. I have moved applications running on a Tomcat server but not wordpress. Is the following correct - Restore the database from backup - Can I create a backup dump using wordpress admin GUI or do I need to manually restore on DB itself. Would you recommend using the 5 minute install - < ? Once wordpress and the database is intalled on hosting site apply any theming to the CMS. Are there any pitfalls I should watch out for ? Am I on the right track ?
If you're just changing servers it's easiest just to move the entire installation over and clone the database (manually from db admin), then update wp-config.php to point to the correct database. If the domain name is changing you'll need to update all the domain name values in the database also. I find this script is the best way to do it - just make sure you keep a backup of the original. If it's for multisite I think you'll also need to update a setting in wp-config.php which contains domain name, have a look in that file to confirm...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, installation" }
How To make Custom page of every Category Hii i have seen many blogs which posted thing in the same design for example if you see this < there page create alwayz in the same style download button and play button and the same td tr combination how can i make this mean did we just have to give links once we create page ? or how this all is possible for maximum time saving
Create `category-<slug>.php` or `category-<ID>.php` in your theme. e.g. category-jazz.php to view songs categorized in jazz category and category-rock.php to view songs categorized in rock category. PS> _This answer is based upon your title. I couldn't understand what you have written in the question._
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, page template, templates" }
Easy way to change custom post type name for permalinks? I've pretty much finished building a site based around a theme that uses a custom post type called portfolio. Now, having just switched my permalinks to a custom structure, posts of that type display as www.mywebsite.com/portfolio/postname I want it to be called 'projects' instead of portfolio so it displays www.mywebsite.com/projects/postname Changing the name throughout the site take forever as it's referenced on numerous occasions in the various php files. Is there an easy way to change this without manually replacing?
I might not have understood your questions fully, but can't you just change the rewrite slug for your custom post type to /projects instead of /portfolio?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, permalinks" }
wp_insert_post_data filter to set category I am trying to set additional "default" categories. I figured by hooking into the `wp_insert_post_data` filter, I could use `$postarr` to set the category. It doesn't seem to be working? Can someone offer advice as to how I would go about doing this? add_filter( 'wp_insert_post_data', 's3x9s_wp_insert_post_data', '99', 2 ); function s3x9s_wp_insert_post_data( $data, $postarr ) { array_push( $postarr['post_category'], 123 ); return $data; }
I think that the best way to set the default category is in the `wp-admin`: _Settings_ > _Writings_ > _Default post Category_ However, I think you're looking for setting more than one category by default. If you look the documentation of `wp_insert_post_data`, there isn't any key such as `post_category`. Perhaps, you should use `publish_post` > Runs when a post is published, or if it is edited and its status is "published". Action function arguments: post ID. There, you should use `wp_set_post_categories` So, the code would be something similar to this: function set_category_by_default( $post_ID ) { wp_set_post_categories( $post_ID, array(123, 124) ) ; } add_action( 'publish_post', 'set_category_by_default', 5, 1 );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development, categories" }
How can I tell if I'm on a custom post type archive page? I have set up a custom post type and a custom taxonomy for it. I'm using the latest version of Wordpress. I believe I should be using the `is_post_type_archive` function, but this seems to be is returning false no matter what. The post type I've set up is called `articles` and the taxonomy is called `editions` I'm trying to access `/editions/september` and the archive page is showing, but the page title is showing as the first post's title. I can fix this if I can figure out how to write a conditional if statement to let me know I am in a custom post type custom taxonomy page. How can I achieve that?
Have you made sure your CPT is using the `'has_archive' => true,` parameter? And try something like; wp_reset_query(); if (is_post_type_archive('articles')){ // do something }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, theme development, custom taxonomy, archives" }
Why is WP-Query spelled like it is? I'm new to PHP and WordPress, and I'm curious: Why is WP-Query capitalized like it is? Is this a PHP naming convention, based on the type of query? Or what? Thanks.
`WP_Query` is a PHP Class, class names are capitalized, with words separated by underscores, as per the Naming Conventions in WordPress Coding Standards.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "wp query" }
Change Posts per page count In the wordpress **settings** => **Reading** => **Blog pages show at most** [input field] **posts** I have it set to 3 posts at the moment. On my index, date archives, tag archives, category archives, search results, etc... All pages that use the loop and paging, it shows 3 posts per page now. My goal is to be able to have different number of results for different pages. ON my index maybe have 3 posts but on search results or archives, show a different number of results per page. Any ideas how to do this?
This will do it: (add to your theme's functions.php) add_action( 'pre_get_posts', 'set_posts_per_page' ); function set_posts_per_page( $query ) { global $wp_the_query; if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) { $query->set( 'posts_per_page', 3 ); } elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_archive() ) ) { $query->set( 'posts_per_page', 5 ); } // Etc.. return $query; }
stackexchange-wordpress
{ "answer_score": 30, "question_score": 20, "tags": "posts, pagination" }
Is there a naming convention for database tables created by a plugin? I have setup my plugin's table to use $wpdb->prefix but aside from that are there any conventions that you should name them; Maybe `$wpdb->prefix.'plugin_'.$tablename` or something. I can't find any documentation and the examples of plugins I have used in the past don't seem to adhere to anything in particular.
I'd say (and that's just my _opinion_ ), that prefixing global available stuff like: * functions * classes * tables * ... should always share the same prefix. Aside from making your code more unique & therefore collision save, it helps when searching for plugin code, plus it serves as branding for your plugin too. Adding `plugin_` to the table name seems like a valid and honorable idea, as it makes the Qs "Does it come from a theme, or a plugin? Where do I have to search for it?" obsolete.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugin development, database" }
SQL select of users by metadata Hi I'm trying to select users with a particular role only, using the following sql statement... SELECT DISTINCT ID, u.user_login, u.user_nicename, u.user_email FROM wp_users u, wp_usermeta m WHERE m.meta_key = 'wp_capabilities' AND m.meta_value LIKE '%supplier%' ORDER BY u.user_registered However, it reurns the whole table. What am I doing wrong? PS this needs to be a SQL select as I'm doing this in myphpadmin to export the data to csv. Thanks in advance!
Double-check your SQL syntax. It sounds like you want to do a `JOIN` ... But you're not building the query correctly. It should be something more like: SELECT u.ID, u.user_login, u.user_nicename, u.user_email FROM $wpdb->users u INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID WHERE m.meta_key = 'wp_capabilities' AND m.meta_value LIKE '%supplier%' ORDER BY u.user_registered You have to tell the query how you're relating the user meta to the user. Also note that I'm using `$wpdb->` rather than `wp_`. This is important if you ever expect to use this query in a plugin on a site with a database prefix other than "wp." If you're running things directly in SQL, though, you should switch back.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "sql" }
Plugin with custom domain OK I will try to explane my problem better. What I need to do is to create a kind o service for my WordPress. From some external web sites I like to send some data to my main WordPress web site through the URL. Lets say I have the web site < On mysite.ext I will install my plugin. Some external web sites can send my ocasionaly some data by a URL (ie: < In that case my plugin must recognize a query variable from the URL and analize the data Note: It is not important to return any information to the external web sites. Just I have to collect the inrormation and process it.
It's more of my personal approach than any kind of best practice, but I find WP's Ajax handler to be easy and logical endpoint for such technical URLs.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, url rewriting, domain" }
How to re-enable admin bar with Buddypress active? (BP bar removed) How do I force WordPress/Buddypress to use the WordPress admin bar on the frontend? I know that I can disable the BP bar with `define( 'BP_DISABLE_ADMIN_BAR', true );` in the config, but the admin bar does not show back up.
In your `wp-config.php`, put this: `define( 'BP_USE_WP_ADMIN_BAR', true );` Note you must put it in wp-config.php, I had it in functions.php first and it did not work.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "buddypress, admin bar" }
How to use a custom post type archive as front page? I'd like to use a custom post type archive as a site's front page, so that is a custom post type archive displayed according to my `archive-{post-type}.php` file. Ideally I would like to alter the query using `is_front_page()` in my `functions.php` file. I tried the following, with a page called "Home" as my front page: add_filter('pre_get_posts', 'my_get_posts'); function my_get_posts($query){ global $wp_the_query; if(is_front_page()&&$wp_the_query===$query){ $query->set('post_type','album'); $query->set('posts_per_page',-1); } return $query; } but the front page is returning the content of "Home" and seems to be ignoring the custom query. What am I doing wrong? Is there a better way, in general, of going about this?
After you have set a static page as your home page you can add this to your `functions.php` and you are good to go. This will call the `archive-POSTTYPE.php` template correctly as well. add_action("pre_get_posts", "custom_front_page"); function custom_front_page($wp_query){ //Ensure this filter isn't applied to the admin area if(is_admin()) { return; } if($wp_query->get('page_id') == get_option('page_on_front')): $wp_query->set('post_type', 'CUSTOM POST TYPE NAME HERE'); $wp_query->set('page_id', ''); //Empty //Set properties that describe the page to reflect that //we aren't really displaying a static page $wp_query->is_page = 0; $wp_query->is_singular = 0; $wp_query->is_post_type_archive = 1; $wp_query->is_archive = 1; endif; }
stackexchange-wordpress
{ "answer_score": 33, "question_score": 19, "tags": "custom post types, functions, wp query, custom post type archives" }
Rewrite on custom post type permalink not working? My theme has a custom post type called 'portfolio'. I want the url to display 'projects' instead. I've change the rewrite on the register_post_type function to 'projects' but it doesn't change the permalinks... 'rewrite' => 'projects' How can I fix this?
rewrite accepts a boolean or array, try: 'rewrite' => array( 'slug' => 'projects' ) make sure to visit your permalinks settings page to flush rewrites after you make the change.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, permalinks, url rewriting" }
How can I include PHP-Code to my post? I would like to use PHP in some posts. These posts should look like normal posts, be in the archive and categories like normal posts an have tags. I don't need PHP in every post, but it would be great if I could use it in some. I saw that it is possible to create custom page templates which seems to be almost what I want, but I want it for posts. How can I get it?
You can edit the `single.php` and/or `content-single.php` files in your theme. Then it depends what you mean by "some". You could apply some conditions to your code (only certain categories, certain tags, certain specific post IDs only, etc.) You could also create a custom post type "myspecialposts" and create `single-myspecialposts.php` (codex)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, php, code" }
Alphanumeric usernames and error message for it I'm facing a problem where I haven't seen proper answer anywhere. What I need help with is this: How can I prevent my users registering non-alphanumeric usernames? To be exact, I could prevent it by using something like: function validate_alphanumeric_underscore($string?) { return preg_match('/^[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*$/',$str); } But what is the string I should/could use and how can I echo error message saying that the username inputted had invalid characters? Cheers!
### Check for alphanumeric For more details, look at the regex Q on SO. $name = 'input string 123"; // Doesn't allow: // Pre-/Appending white space // Not more than one space in between // Non-alphanumeric characters (lower case) if( ! preg_match( "/^[a-z0-9]+([\\s]{1}[a-z0-9]|[a-z0-9])+$/i", $name ) ) { // Output Error Message } // Or: Does only allow // Alphanumeric character (lower & upper case) // Dash & underline "-", "_" - makes (imho) sense if( ! preg_match( "/^[A-Za-z0-9-_",'\s]+$/", $name ) ) { // Output Error Message } ### Error Message You need to do this via Ajax. Best would be to look over the search results. Another (maybe) good reference would be to inspect the code of some ajax login plugins for a "how-to".
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "username, errors" }
How to refine WP-Query with further criteria I have a WP-Query which I pass post IDs to via 'post__in' => explode(',', $my_ids) I then want the ability to refine this list by a custom field value (if present). I have tried including the custom field test in the args for WP-Query but I get my ID list **PLUS** the custom field post IDs (instead of my IDs filtered by the custom field value). I also tried adding a query_post after the WP-Query as a filter but that didnt work at all. How can I filter the query further?
Have you tried using **meta_query**? More details at <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query posts, wp query" }
Got a problem with a widget i am trying to build a widget that would display a list of top authors on sidebar.. This is not my first widget but it is my second one so my apologies if i am way off.. The problem is that when i drag the widget into the side (in admin ofcourse) and saves it apears no where..later when i check i see after refreshing the widgets page it doesent apear to exist.. **here is my widget code:** \--> < i know it rather langthy but can anyone help / give an idea as to why this is happening?
It sticks if you don't include `id_base` in `$control_ops`, when you pass it to WP_Widget in the constructor. Looking at the core code it looks as though `id_base` is actually the first arg to WP_widget and the `$control_ops` array should only carry 'width' and 'height' keys.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, customization" }
Parent/Child pages I find that the parent/child pages in the "Pages" area of WordPress has become a bit confusing since the introduction of the new menu creation area. Using the new menu system, as far as I know I can set a page which is actually itself a child page (in the pages section) to be a parent of a page which is actually itself a parent. Can someone tell me, is the whole parent/child pages scenario now superseded by the new menu system, and unless we plan on using wp_list_pages in the theme should we avoid having child pages altogether and instead just decide where they go in the menu area. What is normaly done on a site that doesn't use wp_list_pages ?
> Using the new menu system, as far as I know I can set a page which is actually itself a child page (in the pages section) to be a parent of a page which is actually itself a parent= **TRUE** > > **What is normaly done on a site that doesn't use wp_list_pages?** I can't speak for all, but I do just as you mentioned. I order the menu myself. If you don't need to manually arrange your sites menu and you find the wp_nav confusing you're probably better off using `wp_list_pages` for you menu, and using the page order in the Edit Pages screen to control your menu order.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, menus, pages, wp list pages" }
How many Custom Post Types to register? My current WordPress site only exists of pages. The structure is as simple as this: example.com/hotels example.com/attractions example.com/restaurants I want to use Custom Post Types to add listings about individual hotels, attractions and restaurants. The new structure will look like this: example.com/hotels/myhotel example.com/attractions/myattraction example.com/restaurants/myrestaurant With myhotel/myattraction/myrestaurant being a Custom Post Type. All listings share the exact same custom fields. My Question: Do I need to create 3 Custom Post Types (hotel/attraction/restaurant) or should I register just 1 "global" custom post type - eg called "Place" - and specify if its a hotel/attraction/restaurant using hierarchical Custom Taxonomies? What are the advantages/disadvantages of these different approaches? Thanks!
Personally I would structure it like a CPT for each Hotels, Attractions, Restaurants. Then a custom taxonomy that ties them together for instance "Places" with children like "Locations", etc. If the site has a lot of connected data it is a really good idea to sketch out the relationships on paper or using software like Visio so you can visually see how it all fits.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, custom taxonomy" }
editor text cut off when using 2 spaces (after periods) I have noticed that my TinyMCE editor in Wordpress MU 2.9.2 loses text after a double space when you save a blog post. This is a problem because some users habitually use two spaces after a period. In these two examples, there are two spaces between "test" and "test": * "test test" ("test__test") becomes "test" when the blog is saved * "test test, the rest of my long blog post" ("test__test,_the_rest_of_my_long_blog_post") becomes "test" when the blog is saved _**Edit_** : I updated to WP 3.2.1 and can confirm that this is still an issue.
Problem solved: In 2.9.2 under "New Blog Defaults", the field "Encoding for pages and feeds" was blank and should have been `UTF-8`. When I updated this field on all blogs, the problem went away. In 3.2.1 you can edit this value on a blog by blog basis on the reading settings page: `/wp-admin/options-reading.php`. I'm not sure what the default value for new blogs in 3.2.1 is, or if there is somewhere to change the default, but I'm guessing it is `UTF-8`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "tinymce" }
How to disable admin flyout menus? Seriously, I hate flyout menus with a passion, and now they're popping up all over the place in the admin screen. (They are particularly heinous when you use the blue admin theme, because they add a dark arrow. Eye dirt.) How do I disable the flyout menu? They add zero functionality and usability to my workflow. Thanks
It's a bit of a workarround but here you go: function remove_flyout() { echo '<style type="text/css"> .js #adminmenu .wp-submenu.sub-open { display: none; } </style>'; } add_action('admin_head', 'remove_flyout'); Put it in your functions.php
stackexchange-wordpress
{ "answer_score": 0, "question_score": 3, "tags": "wp admin, javascript, admin menu" }
Where did the screen options menu go? Where did the screen options menu go? I can't seem to find it anywhere in the new "improved" admin interface. Screenshots from the dashboard page: !enter image description here !enter image description here
Apparently, they decided to move it under the un-helpful "help" menu in the main admin bar. !enter image description here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "wp admin, screen options" }
Problem with <code> tag Where you can see it: < The first button is my code, as it should appear. The second button is within `<pre><code></pre></code>` tags to show users how I made the button appear. But instead of showing the code, the button is generated. **How can I get WordPress' code tag to work for ALL code? HTML, PHP, and CSS. Something I can paste in my functions would be preferred.** The actual code for the button (a shortcode) [pdf href=" of Independence[/pdf]
You can display a shortcode by using two (or three) square brackets at the open and close, e.g. `[[[pdf href=" of Independence[/pdf]]]` In my experience, a standalone shortcode just needs two whereas one that wraps needs three on each end, even though I've seen it said that it should work just two in either case.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, code" }
Wordpress wallpaper Plugin hii I am making a site related to entertainment which also has Movies Wallpapers category where i want that i can add new Movie wallpapers in single post and People can View and download them easily ? So it will be very difficult to check all Available Plugins So i need suggestions which plugin is better for my Idea Site ?
What you could do is use NextGen Gallery and then in the picture description provide a download link to the wall paper or the original picture file. You can find it here: <
stackexchange-wordpress
{ "answer_score": 3, "question_score": -2, "tags": "plugin recommendation" }
How to add post featured image url to inline background url()? I'd like to get a post's featured image and use it in the style="background: url()" of the post. I thought this would do it, but alas I was wrong because this outputs the whole (img src=""> stuff. <div style="background: url(<?php the_post_thumbnail( 'thumbnail' ); ?> ) !important;">adasdasdasd </div> I tried get_post_thumbnail but don't think I have the format right. Any thoughts?
You just need to retrieve the src attribute of the thumbnail: $thumb_src = wp_get_attachment_image_src ( get_post_thumbnail_id('thumbnail')); `$thumb_src` is then an array containg the url, width and height of the thumbnail image. So something like... <div style="background: url(<?php echo $thumb_src[0];?> ) !important;">adasdasdasd </div> should work.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "post thumbnails" }
Facebook and WordPress Is there a way to create a login/register with facebook and facebook comments on my wordpress site without using plugins? Some sort of a guide would be appreciated.
You can use the Facebook Comments for WordPress plugin or the Disqus Comment System, which allows comment login using Google, Twitter, Facebook, or OpenID accounts, and is totally import/export compatible with WP comments.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "login, facebook" }
How to edit posts with the new wp_editor api? I am using bbPress 2x and modified the plugin to use the new wp_editor in place of the textarea for adding new topics and replies. This part works beautifully. Where I am stuck is when a person clicks edit for a topic or a reply. The post content is not showing up in the editor. I'm probably just missing something really stupid, and hoping someone can chime in on how to fix this last piece. Here is what I am using: ` $tabindex = bbp_get_tab_index(); $settings = array( 'wpautop' => true, 'media_buttons' => true, 'editor_class' => 'tumble', 'tabindex' => $tabindex ); wp_editor( '', 'bbp_topic_content', $settings ); ` thanks **EDIT** Just got an answer to my question, and it works great Thanks go out to: < ` $post = get_post($post_id, 'OBJECT'); wp_editor(esc_html($post->post_content), 'textarea01', $settings); `
For the sake of completeness, I am going to post an answer based on the solution you edited in your question. $post = get_post( $post_id, 'OBJECT' ); wp_editor( esc_html( $post->post_content ), 'textarea01', $settings ); This would escape the HTML too so if you are editing a post you might want to replace the last line with: wp_editor( $post->post_content, 'textarea01', $settings );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 6, "tags": "editor, bbpress" }
How to list Tags using get_tags in an html table? Any suggestions on the simplest way to display tags using get_tags in an html table (4 columns across) ? Example: Tag 1 | Tag2 | Tag 3 | Tag 4 Tag 5 | Tag 6 | Tag 7 | Tag 8 I'm using the following code to display tags, I found it in codex.: $tags = get_tags(); $html = '<div class="post_tags">'; foreach ($tags as $tag){ $tag_link = get_tag_link($tag->term_id); $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>"; $html .= "{$tag->name}</a>"; } $html .= '</div>'; echo $html;
This is what I tried and it works well. I am using `array_chunk`, but I'm also adding a check to see if a chunk has less than 4 values (as you want 4 columns), then just add a blank `<td>`, which will avoid the mark up from breaking. <?php $tags = get_tags(array('hide_empty' => false)); $tag_groups = array_chunk($tags, 4); $t = '<table>'; foreach($tag_groups as $tag_single) { $t .= '<tr>'; for($i = 0; $i < 4; $i++) { if(isset($tag_single[$i]) && !empty($tag_single[$i])) { $tag_link = get_tag_link($tag_single[$i]->term_id); $t .= "<td><a href='".$tag_link."' title='".$tag_single[$i]->name."'>".$tag_single[$i]->name."</a></td>"; } else { $t .= "<td></td>"; } } $t .= '</tr>'; } echo $t .= "</table>"; ?> Hope it helps!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "tags, html, table" }