INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Which contact form plugin passes Outlook junk / spam filters? I'd like to know which contact form plugin has the best header and email creation so that Outlook does not filter it as junk mail. I'm using jigowatts simple php contact form. I am going to test the AJAX WP plugin version but would like to hear from everyone and what they use to get emails accepted by Outlook. Thanks
Contact Form 7 is working well and no emails are getting filtered as junk in outlook
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin contact form 7" }
How to filter out Categories for specific post types on Wordpress Admin? How can i programatically change the Category selection menu on wp-admin? is there a hook or filter to edit the Category List? My objective is to filter out specific categories for specific post-types, for example: I have the categories: Sports,Players and Coaches under the post-types: People and Activities I want to filter the Sports Category out of the People Post-type.
I went down the rabbit hole with this a few weeks ago. Never quite got it working right. These might lead you in the right direction: < <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, wp admin, taxonomy" }
Create wordpress dashboard metabox which spans all columns Is it possible to create a wordpress dashboard plugin that will span all the columns that the user has chosen to display? I know how to force the user to only display one column but I would rather leave them that freedom and span the number of columns that they have selected. Be it one, two, three or four. Thanks.
No you can't - a metabox cannot span more than one column, and so the width of the metabox is determined by how many columns there are.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, dashboard" }
Including a post title in a twitter link Im trying to make a Twitter button on each article of my blog. This is the code I use on single.php <a href=" echo urlencode(get_the_title()); ?>"> Tweet this! </a> The problem is that I have a blog post with this title: > Give format to “bodytext” and when I tweet it, the quotes appear as > Give format to &#8220;bodytext&#8221; What should I do?
The problem is that `get_the_title()` will pass the title through a filter that texturizes the quotes. So a regular " becomes a curly quote (") and `urlencode()` will break it. So instead, write your own title function and use that: function my_get_the_title() { global $post; return $post->post_title; } This should bypass any unwanted filters and let you work with regular quotes.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "twitter, get the title" }
Where is wp() function definition? In WordPress source code, there is one point I can not understand. In /wp-blog-header.php, there is a call to wp() function. However, I can not find any definition for that function. How this call don't cause error?
Just follow the code :). Before calling `wp()`, `/wp-blog-header.php` loads `/wp-load.php` (which assuming you have correctly installed WordPress) loads `/wp-config.php`. At the bottom of that file, it calls `/wp-settings.php`. This file loads a lot of other files, initialising the core parts of WordPress. Amongst them, is the `wp-includes/functions.php` file. It's inside this file that `wp()` is defined. Once `/wp-settings.php` has finished loading all the files, `wp()` is then called - this 'starts' WordPress (interpreting the incoming url, processing it into a query, choosing a template and finally outputting the content and sending into the user.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php" }
Navigation menu displays permalinks I am creating a theme from scratch and the navigation menu is disturbing me because it is displaying the permalinks after the menu item name. See this picture < Link name (#permalink) is the result of `wp_nav_menu()` Setting e.g. `$before/$after` \- yields text before/after (#permalink) The (#permalink) part is not displayed in the source. Since it's only Pages I tried wp_list_pages(), but that gives me the same result. Any ideas on how to remove those permalinks? I believe there is some 'default' setting for how links/menu items should be displayed but I don't know where to look. Thanks!
Since the (#url) isn't displayed in the source, I suspect this is being placed there by CSS with a rule like: #menu a:after { content: "#"attr(href); } If I had to guess it's a print stylesheet run amok, possibly from a plugin.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus, permalinks, navigation" }
How to define category ID in an array? I have the following: <?php if ( array( 'is_category', 'is_tag' ) ) { ?> What I want to do is (that doesn't quite work): <?php if ( array( 'is_category('13')', 'is_tag' ) ) { ?> So what I'm asking is, how can I include that ID in code that will work? That's how I would do it anywhere outside of an array, so I am unsure exactly how to include it here. Thanks
As Geert pointed out, your current conditional will always be true. An if() construct needs to be fed an expression. You're feeding it a valid array, so that's _true_. Always. So far this is basic PHP, regardless of whether in a WP environment or not. As can be read in Chris_O's comment if ( is_category('some-cat') && is_tag('some-tag') ) { // do something } will do the trick. `'some-cat'` and `'some-tag'` may be the category/tag slug, id or title. The codex page on conditional tags explains the use of these rather well.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -2, "tags": "categories, array, include, exclude, id" }
Exclude main blog from get_blogs_of_user I use WordPress Multisite and in the sidebar i have a box that shows a list of blogs the logged in user is a member of. I'm looking for a way to exclude the mainblog from this list. The main blog ID is 1 **Here is parts of the code I use:** <?php // Gets user-info ?> <?php global $current_user; get_currentuserinfo(); $user_info = get_userdata(1); $user_id = $current_user->ID; ?> <?php // start the loop ?> <?php $user_blogs = get_blogs_of_user( $user_id ); echo '<div>'; foreach ($user_blogs AS $user_blog) { echo '';?> <?php // lists user blogs ?> <?php echo ''.$user_blog->blogname.' '; ?> Can anyone help me? :)
If you drop this line in your code, you will see all the properties of $user_blogs. `echo '<pre>'.print_r($user_blogs,true).'</pre>';` One of them is `userblog_id`, so you just have to check against it before echoing the blogname. <?php $user_blogs = get_blogs_of_user( $user_id ); if (!$user_blogs) { echo 'no blogs'; } else { echo '<div><ul>'; foreach ( $user_blogs as $user_blog ) { if ( $user_blog->userblog_id != get_current_blog_id() ) { echo '<li>' . $user_blog->blogname . '</li>'; } } echo '</ul></div>'; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "multisite, user meta, id, terms" }
Post Ancestor and Child Post in Custom Post Type !enter image description here Hierarchical structure of custom post type "Book" (for example). When we are on `Post 2-95`, I want to know: * Does the post has this post ancestor(`Post 1-31`)? * Does it have child posts(`Post 3-19`, `Post 3-10`)? Then, if it has: * an ancestor post: retrieve (object) of this post. * a child posts: retrieve (objects) of these posts.
Given a post represented by a post object `$p`, you can find out if post 31 is the parent via: if($p->post_parent == 31){ // it is! } else { // it isn't } To figure out the children, something like: $posts = get_posts(array( 'post_parent' => $p->ID, 'post_type' => $p->post_type )); // if there are children, they will be contained in `$posts` Finally, to determine how many levels deep down the hierarchy you are, you will need to recurse up the hierarchy `$p->parent_post == 0`, and then count how many times you needed to do that. e.g. $level = 1; while($parent->parent_post != 0){ $level++; $parent = get_post($parent->parent_post); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "custom post types, directory, customization" }
Using a menu walker add a custom item at the end of the menu's items I need to add a search field at the end of a menu in a list item. I've been looking at walkers but finding it really hard to figure out what is the last item (or even get the total). Also where would i add the code for the custom item. I've currently got; class mainNav_walker extends Walker_Nav_Menu { public function start_el( &$output, $item, $depth, $args ) { //print_r($item); $output .= $this->custom_content( $item ); parent::start_el( &$output, $item, $depth, $args ); } protected function custom_content( $item ) { // add <li>SEARCH FIELD HERE?</li> } }
You don't need a walker in this case. A filter called `wp_nav_menu_items` is available. It allows you to edit the list items of a menu. Just append your own list item with search field. add_filter( 'wp_nav_menu_items', 'add_search_to_nav', 10, 2 ); function add_search_to_nav( $items, $args ) { $items .= '<li>SEARCH</li>'; return $items; } Note: if you only want to target a specific menu, a dynamic filter exists: `wp_nav_menu_{$menu->slug}_items`
stackexchange-wordpress
{ "answer_score": 20, "question_score": 12, "tags": "menus, walker" }
How do I set the sizes of my thumbnails when inserting a [gallery]? A really simple thing, yet my images are uploaded as about 500px wide, I have them selected as full size, yet when I use the [gallery] shortcode, it crops the thumbnails to 100w x 75h. This isn't even the thumbnail size I have set in my media settings! My page is here
try `[gallery size="thumbnail"]` <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, gallery" }
Remove "minor-publishing" div from Publish admin metabox I want to remove the `#minor-publishing` `div` from the Publish admin metabox. I came across How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button and < but they either remove it by css or custom-code their metabox. Is there a way to remove the div by hooking on to some action and modifying the html that will be outputted for that metabox? How to Move the Author Metabox into the "Publish" metabox? modifies the html output by _adding_ code to it. What I need is to _remove_ the entire `#minor-publishing` `div` from the html that will be output for the Publish admin metabox. Thanks in advance.
In short- no. The html in question is hard-coded in the `post_submit_meta_box` callback function. You can, of course de-register the publish metabox and re-register your own which mimics `post_submit_meta_box` (but making your alterations) and being sure to keep the names of the inputs exactly the same. This method has been outlined the following posts where a core metabox is required to be edited.: * custom post type taxonomies UI radiobuttons not checkboxes * Custom-Taxonomy as categories: Remove "most-used" tab? It's a lengthy function though - and would break if core ever changed decided to change the names of the inputs (though very unlikely). In this situation I would probably recommend a CSS or javascript work-around....
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin, metabox, editor, publish, customization" }
Hide root site in Multisite install I recently setup a WordPress multisite install using subdomains and the WordPress MU domain mapping plugin. When I initially setup the domain mapping plugin, I set the root ( and < to redirect to blog ID 2 (ie. www.domain.com). However, when I do this the redirect on the root prevents me from accessing the Network admin page. Is there a way I can change the configuration to enable me to still access the Network admin page whilst redirecting the root site to www?
I was in a similar situation recently. I ended up putting the root site on a random subdomain (eg `ms.domain.com`) With the intention of never using the root site. With that done, I created a plugin to activate only on the main (root) site. The plugin hooks into a action that fires only on the front end (`template_redirect`). From there, call `wp_redirect` to send your visitors to where they need to be. <?php add_action('template_redirect', 'wpse52298_redirect'); /* * Redirects all requests to the front end to another site * * @uses wp_redirect */ function wpse52298_redirect() { // change this $to = ' wp_redirect(esc_url($to)); exit(); } **Cons:** * Loads basically all of WP before redirecting * Not as fast as redirecting in htaccess **Pros:** * Easy to maintain * No htaccess foo required As a plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, domain mapping, configuration" }
get attachments for all posts of particular post type I'm making a widget that shows a set of images from recent custom posts. I want to run the following query: SELECT p.* FROM wp_posts p WHERE post_type='attachment' AND post_mime_type LIKE 'image%' AND post_parent IN ( SELECT ID FROM wp_posts WHERE post_type ='my_custom_post_type' ) ORDER BY post_date DESC LIMIT 10; and receive an array of attachment objects. I am unclear on the canonical WordPress method for doing something like this. Where should I start?
It seems like a bit of a waste to run through two loops just to use some built in API functions that weren't designed for a use case like this. I think you're better off to use your SQL combined with the wpdb class -- faster and cleaner. Example (with modified SQL): <?php function wpse52315_get_attach() { global $wpdb; $res = $wpdb->get_results("select p1.* FROM {$wpdb->posts} p1, {$wpdb->posts} p2 WHERE p1.post_parent = p2.ID AND p1.post_mime_type LIKE 'image%' AND p2.post_type = 'your_cpt' ORDER BY p2.post_date LIMIT 10;" ); return $res; }
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "custom post types, query, attachments" }
Add Post Format Support to Twentyeleven Child Theme On a Twentyeleven child theme's functions.php file I attempted to add video post format support using: add_theme_support('post-formats', array( 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video', 'audio')); ...adding the 'video' format to the array. But it would not work until I deleted the function in the parent theme. Obviously, when the theme is updated and functions.php is overwritten, I will lose the change. Whats the best way to avoid this and add support to my child theme? Thanks.
try running your code with a lower priority: add_action( 'after_setup_theme', 'my_twentyeleven_setup', 20 ); function my_twentyeleven_setup(){ add_theme_support('post-formats', array( 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video', 'audio', )); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme twenty eleven, post formats, add theme support" }
Filter the_content() in the Quote Post Format to Display Quotes I'm customizing a theme for a client and I want to leverage post formats. On the quote post format I would like the_content(); to be wrapped in a two spans that contains quotation marks that I could style and position. Is this possible? Thanks.
**Try** $content = get_the_content(); $content = '<span>"</span>'.$content.'<span>"</span>'; echo apply_filters('the_content', $content); **CSS Solution:** <blockquote> <?php the_content(); ?> </blockquote> blockquote:before{ content: '"'; } blockquote:after{ content: '"'; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "the content, post formats" }
WP_Query pagination using only numbers instead of /page/1 on URL I don't get whats happening here. I'm on a child-page template, generating a WP_Query for Custom Post Types on the fly, like this: $notrel = new WP_Query(array( 'post_type' => $type, 'posts_per_page' => $perpage, 'monthnum' => $mes, 'year' => $ano, 'paged' => $paged )); Loops and $_GET filters for `post_type`, `monthnum` and `year`are all working perfectly. But pagination is giving me trouble. A) If i try the URL ` i get `paged = 1`. B) On the other hand, ` correctly gives `paged = 4` but pagination doesn't work since `next_posts_link` automatically shapes URLs like A. I guess `/page/4/` is standard, so why is it not working here? Is it maybe the rewrite parameter on register_post_type? **EDIT:** still not solved, se this -> paginate_links() adds empty href to first page and previous link
I didn't really solve it, but got around with the help of Passing custom args in paginate_links and Custom paging function. Initially I even thought of writing a patch to `next_posts_link`, but as it turns out, the URL formatting problem lies way below in the function soup, and that is really a downer when all I wanted was to reuse some earlier code that went into this template when it was still static. My solution for now was to leave it all behind and start fresh with `paginate_links()`. Turns out that paginate_links doesn't care about permalink structure and always appends `?page=4` to the URL which just makes a lot more sense. :) UPDATE: Followinfg along, I got this problem -> paginate_links() adds empty href to first page and previous link which was properly solved after all. :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, wp query, pagination" }
How to pull a list of posts in a category while exluding posts in subcategories of the category I'm using a get_posts() call to pull a list of posts in a specific category. However, the recordset also includes posts in subcategories of the target category. How can I exclude subcategories from the query? $cat = get_query_var( 'cat' ); $catHidden=get_cat_ID('hidden'); $args = array('cat' => "$cat,-$catHidden"); $myposts = get_posts($args);
If you use `category__in` and `category__not_in` instead, it will only pull the posts that are in that category, not the subcategories as well. For your code, this would look something like this: $args = array( 'category__in' => $cat, 'category__not_in' => $catHidden ); Note: this will only exclude posts that are directly in the category as well. If you want to exclude posts in that category and the subcategories of it, use `cat` with the negative syntax. Also, if you need more powerful querying, this can be found with the `tax_query` parameter, which will allow you to set an `include_children` parameter for each taxonomy and term you are querying for.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories, get posts" }
Archive pages have smaller font then the rest of my website I have my awesome wordpress website here that I have been working on for weeks now and all is great with it except for one thing! For some reason when you try to look at the archives pages the whole page's font gets smaller. I mean, any navigation link, text link, paragraphs, titles, etc. I've checked my CSS and files but I can't seem to find out what is different with just that one page. I've used firebug to find out maybe the scripting is off in a section but I've had no luck finding anything different. I've tried to copy over from the twentyeleven archive.php page so I'd basically start as new as I could and then add in my extras but that didn't seem to work either. Had anyone come across this issue before or has advice as to what might be happening? I appreciate any feedback!
You're applying a font size of 12px to any objects with the class `.date`, but, this class is being applied to the body element because it's a date archive. So make your `.date` rule more specific. Protip: Using a non-IE browser, press f12 to bring up the dev tools and inspect the elements
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "css, archives" }
wp_logout_url redirects to incorrect page because of pagination Following a Wordpress Pagination tutorial, `wp_logout_url( get_permalink() );` no longer redirects to the correct page. Instead of redirecting to say `domain.com/page/2/`, it redirects me to one of the posts in the listed category. Is there a way to fix this? global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages > 1){ $current_page = max(1, get_query_var('paged')); echo '<div class="page_nav">'; echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'current' => $current_page, 'total' => $total_pages, 'prev_text' => 'Prev', 'next_text' => 'Next' )); echo '</div>'; }
It's not clear, but I'm assuming you want a 'log out' url, that brings the user back to the current page? `get_permalink()` however, get's the permalink of the _current post_ in the loop (if you're using it outside the loop, you'll find that it takes the user to the _last_ post in the loop after they log out). To get the url of whatever page you're currently on, you can use `$_SERVER['REQUEST_URI'];` (if there is a WordPress function that does this, apart from using `add_query_arg()` I would like to know it...) So try: wp_logout_url( $_SERVER['REQUEST_URI'] );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "permalinks, pagination, redirect, logout" }
Is there a way to make the main page only display a brief description of the full article? I want to make a new blog which only has a brief description of the article on the main page, instead of a shortened version of it. I want to make the brief description of the article myself. Is there any way to do this, or any plugin which allows it?
You need to turn on Excerpts. They are hidden onder the 'screen options' in the right top corner of add/edit screens. And on the front page call `the_exerpt()` instead of `the_content()`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, posts" }
how can I go about creating a dashboard in the post section of wordpress admin I am trying to create a dashboard in post section of wordpress admin area. I want it just underneath the Publish dashboard. like for example this code here place a dashboard in immediately when I log into the admin area. // Create the function to output the contents of our Dashboard Widget function example_dashboard_widget_function() { // Display whatever it is you want to show echo "Hello World, I'm a great Dashboard Widget"; } // Create the function use in the action hook function example_add_dashboard_widgets() { wp_add_dashboard_widget('example_dashboard_widget', 'Example Dashboard Widget', 'example_dashboard_widget_function'); } // Hook into the 'wp_dashboard_setup' action to register our other functions add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );
You'll want to look into the `add_menu_page()` function and then use the `$position` parameter to place it in the menu where you want it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "dashboard" }
using pre_get_posts for search results not found function hotlinkers_wp_query($query) { if ( !$query->is_admin && $query->is_search) { $search_query = str_replace('-',' ', $query->query_vars['s']); $query->set('s', $search_query); } return $query; } add_action('pre_get_posts', 'hotlinkers_wp_query'); this is for the search results found, on search.php i have an else, so if no searches are found it shows 15 random posts (using wp query) wanted to avoid that if possible to do via pre_get_posts.
Like others have said you can't use pre get posts since there is no way of knowing if the search returned any posts. I would also say that the if else is a very clean way to do it and might be the better choice if anyone else is going to be working on this. But if you really wanted to do it with a filter on either the posts_results or the_posts to return the replacement posts that should be shown if the search is empty. <?php add_filter('the_posts', 'np_replace_empty_search', 10, 2); function np_replace_empty_search($posts, $wp_query){ if($wp_query->is_search && empty($posts)){ $new_query = new WP_Query(); return $new_query->posts; } return $posts; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp query, search, pre get posts" }
Counting words in a post How can I count words in a post? Something like the one displayed just below the post? Can someone please show me the code for getting this. I have been searching everywhere.
How hard did you search? I searched Google for "wordpress count words in post" and found a function for it in the first result! Put this in `functions.php`: function prefix_wcount(){ ob_start(); the_content(); $content = ob_get_clean(); return sizeof(explode(" ", $content)); } Then call it in the template like this: <?php echo prefix_wcount(); ?>
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "posts" }
how do I get rid of the links and all the links related menu items on the admin ui? Since I won't be using the built-in links feature of wordpress, I see no reason in keeping its related menu items on the admin ui causing nothing but clutter. How do I do that?
In your theme's _functions.php_ : function wpse52464_admin_ui_fixes() { remove_menu_page('link-manager.php'); } add_action('admin_menu', 'wpse52464_admin_ui_fixes');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "links, admin menu" }
How would one change the default url structure of attachments? When I click on post images it redirects in a page with a url like this: ` Can I set the default image link like ` instead of ` Also how to style the attachments page? Should I have a page like attachments.php?
Navigate to: Dashboard -> Settings -> Media Check this box: Organize my uploads into month- and year-based folders. Save changes. then Navigate to: Dashboard -> Settings -> Permalinks Select "Post name" under "Common Settings" Save changes. As far as styling an attachment page, you can either open up your page template file, and add a conditional check for is_attachment() or you can make an attachment.php file in your template directory. Read more about the template hierarchy for attachment display. <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "posts, images, attachments" }
How did you incorporate WooCommerce in your own WordPress theme? This has most probably been asked before, but I really need to show WooCommerce products in my template, but I don't know what hooks to add where. It's my first time working with WooCommerce. Can anybody maybe help me out? Quick step by steps of the process are all I'm asking? And a little more advice would be **greatly** appreciated. Also, just a URL explaining the complete process would be bonus, as I can't find anything on the net at the moment.
Generally, Woo is integrated by the use of shortcodes in pages. This is to say, if you want a page to have the cart, create a "Cart" page and put the `[woocommerce_cart]` shortcode in the content. In fact, Woo adds two new buttons to your WYSIWYG editor to insert the shortcodes for you! This wouldn't be a very good standalone plugin if it required theme editing just to function. While you can hook directly into the theme, it's not necessary - nor is it really advisable, since you may want to change themes without rewriting all your custom hooks.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "templates, plugins" }
displaying tags in a widget I have a widget which displays the latest projects as thumbnails on my website. When I mouse over a thumbnail the project title appears; this is the code for title: `<h2><?php echo get_the_title(); ?></h2>` So, I'm thinking to display also the tags from that specific project, to be something like beautiful, nature, landscape Is this possible, or could you give me some suggestions on how to achieve this ? Thanks!
By what code you've posted, it seems like you've got a secondary loop set up (using a `WP_Query` object). So to display the current' posts tags you can use: * `the_tags` \- to print a list of the post's tags * `wp_tag_cloud` \- to print a tag cloud. * `get_the_tags` \- to return an array of tag objects, which you can then use to display the tags however you'd like.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "widgets, tags" }
Where to find the source code of a widget? i would like to find the source code of the _widgets_ , would you know where to find them? I found the class WP_Widget, but i would like to find, for example, the widget with the last articles. Thanks
The default widgets are defined in `wp-includes/default-widgets.php`. To find specific code search the Codex or use queryposts.com. The best tool is your IDE (integrated development environment). All IDEs offer a full text search in a set of files. Here a screen shot from Eclipse PDT !enter image description here As you can see it is really flexible – and it's fast too. See also this question for a basic guide on how to work with WordPress in an IDE.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 5, "tags": "widgets" }
Is there a way to separate wordpress titles from their posts? Basically I am coding my own theme, and I would like to have my titles listed on the left hand side, so that on clicking the title, the corresponding body opens up on the right. How can I list these two interlinked items separate from each other, but still have the title reference the right post. The problem I'm anticipating is that I might have to construct a different loop for the titles section and the body section each. Once I've done this, I don't see how I can link them together so that the jQuery I use would link the title to the corresponding body. Much thanks in advance
**Here is an idea:** 1. Use `get_posts()` to get posts you want. 2. On the right hand side show titles via `foreach`. 3. use `setup_postdata()` on right hand side loop to get post content. 4. You can use jquery tabs to show and hide post content or just use jquery. 5. Don't do `get_posts()` twice or use ajax because you already got contents when you did `get_posts()` on no. 1 **How do you relate contents:** So you have content of same posts on two part of the page. How do you relate them to use on jquery. Well, you can use post id off course. Check for same id on the content area if id matches with title show the content. <h1 id="post_<?php the_ID(); ?>><?php the_title(); ?></h1> ... ... <div id="post_content_<?php the_ID(); ?>>the_content();</div> ... ...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, loop, title" }
Different fields in My Profile page depending on user role So I understand that I can user current_user_can to check the role of the current logged in user. But what I would like to do is show these different fields to the site Admin. So for example the contributor role may have different custom fields than the subscriber. Each role would see their relative fields but the Admin would see a whole list of all fields in a contributor profile page and subscriber profile page. Is there a way to allow the admin to only see certain fields of a user profile page? I hope this makes sense to you out there! Thanks in advance.
I'll post whole code which have to be in functions.php it's legit WP valid code, how it should be done :) This should work, of course you have to put your role name in switch. **UPDATED FOR PERFORMANCE:** `add_action( 'show_user_profile', 'user_fields_for_admin', 10);` `add_action( 'edit_user_profile', 'user_fields_for_admin', 10);` function user_fields_for_admin( $user ){ switch ($user->roles[0]) { case 'SOME ROLE': echo '<b>This is the role specific fields</b>'; echo 'fields....'; break; case 'SOME ANOTHER ROLE': echo '<b>This is the role specific fields</b>'; echo 'fields....'; break; } }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "pages, customization, profiles" }
Add submenus to Theme options menu My theme currently has a single menu on the left hand sidebar of WP admin. I want to include submenus on that menu. How can I add, for example, a single submenu item to the "Theme Options" menu below? add_menu_page( "My Theme Options", "Theme Options", 'edit_themes', basename(__FILE__), 'my_admin', get_bloginfo('template_directory') .'/img/favicon.png' );
To do that, you would use **`add_submenu_page()`**. But I would **strongly recommend** against making submenu pages for Theme options. To begin with, you should be using **`add_theme_page()`** for your Theme options page, so that your Theme options page itself is properly placed as an **Appearance** sub-menu page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, add menu page" }
When Installing a Plugin Where do I Move Template Files to? I just installed a WP plugin cron-view I can't find where it is or what it's actually done. When going to the install directions though - < I get: "Upload your post template files (see the Description for details on configuring these), and choose them through the new menu." But that assumes that you know where (relative to the root directory) this is supposed to be put. Thoughts would be appreciated
After activation, the plugin is available under the Tools menu > What's in Cron? The text telling you to upload template files is from another one of his plugins, custom post template, looks like a little copy / paste error there. Cron View has no template files to move.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
I'm getting a 404 message when I try to access wpadmin I can't access wp-admin at all after changing wp-config folder permission for hardening my security. The content for the site load find, I cant access wp-admin at all, all I get is 404 message.
Delete .htaccess type in domain.com/wp-login.php login. Dashboard -> Settings -> Permalinks -> Save. (just automatically recreates your .htaccess again). If the problem persists. Try disabling plugins. Enable plugins 1 by 1 until the problem occurs again. That will narrow down the faulty plugin.
stackexchange-wordpress
{ "answer_score": 12, "question_score": 10, "tags": "wp admin, 404 error" }
page url in shortcode I have a problem. I'm using a custom shortcode to try to get the url. If the shortcode is inside a post then it gets the post url. When I open the post on a category list, this post shortcode works correctly. extract(shortcode_atts(array( 'gurl' => get_permalink(), ), $atts)); But when i try to add this shortcode in widget text, I get the last post url. Tell me please how I can get the post url when the shortcode is in a widget.
Depending on how the page's query and loop are constructed, when you access the post object from the sidebar or footer, you sometimes get the last post in the loop rather than the page itself. You can ensure you're getting the original (page) object by running wp_reset_query() from inside your widget (before you access the post object or run any functions that assume the current post as their target). One caveat here: make sure there's nothing _after_ your widget that would be affected by this post reset.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "widgets, urls, shortcode" }
loop inside a loop : search for posts in the same category Could someone tell me how i could make this work? i have a loop, and i would like to create another loop to find the other posts from the same category : but this does not work : <?php while ( have_posts() ) : the_post(); ?> <?php /* How to display all other posts. */ ?> <?php $monid = the_ID(); $cat = get_the_category($monid); //this works $args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => $cat ); $myposts = get_posts( $args ); var_dump($myposts); //this don't ?> <ul> </ul> i found this topic Loop inside the loop but it does not really work for me : any help? thanks a lot
Okay, it works like that : <?php while ( have_posts() ) : the_post(); ?> <?php $cats = get_the_category(); $cat_obj = array_shift($cats); var_dump($cat_obj); $cat_id = (int) $cat_obj->cat_ID; $qq = query_posts( 'cat=$cat_id&posts_per_page=1' ); //var_dump($qq); foreach($qq as $q2){ var_dump($q2->post_content); } wp_reset_query(); ?> i hope this can help
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "loop, get posts, categories" }
How to get 4 Posts after the 5 most recent ones Well, I think the question might be a bit confusing. But well, I want to get the recent 4 posts, ignoring the first five recent posts. So in short the sixth, seventh, eighth and ninth - most recent posts.
Simple. WordPress provides a function called `get_posts()` that lets you get posts in any order. Basically, `get_posts()` will retrieve the 5 most recent posts by default. To get 4 posts, ignoring the 5 most recent, you'd set the `numberposts` and `offset` parameters - `offset` tells the function how many posts to skip. $args = array( 'numberposts' => 4, 'offset' => 5, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish' ); $posts = get_posts( $args ); Now you have an array of posts the 4 latest posts (ignoring the 5 most recent), ordered by date.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "query posts, get posts" }
Should I escape wordpress functions like the_title, the_excerpt, the_content I had look at the code but I couldnt see any escaping on funcions like `the_title` `the_content` `the_excerpt`etc. I might not be reading it right. Do I need to escape these functions in theme development like: `esc_html ( the_title () )` Edit: as pointed out in the answers below the above code is wrong regardless - the code should have read `esc_html ( get_the_title () )`
Escaping depends entirely on the context in which you are using the functions. What is safe for displaying inside `<h1>` tags, is not necessarily safe to display for the `value` attribute of an input field, and even that wouldn't necessarily be safe as a `href` attribute value.... In short - perform the sanitisation yourself as you output it. Though in the case of `the_title ()` or `get_the_title ()`, `esc_html` is not necessary, since WordPress applies the following functions: * `convert_chars` * `wptexturize` **Note:** `the_title` prints the title - so `esc_html ( the_title () )` won't work. Similarly, `the_content` prints the content (in any case, you'd expect the content to display HTML).
stackexchange-wordpress
{ "answer_score": 16, "question_score": 18, "tags": "security, escaping" }
Posts Page Featured Image I have created a theme that uses a featured image on every page. In settings, I have setup my "Posts Page" to be "news"...how do I get the featured image from "news" to display? The following will display the id of my posts page: <?php $page_for_posts = get_option( 'page_for_posts' ); echo $page_for_posts; ?> So I was thinking that this would display the featured image for my posts page: <?php $page_for_posts = get_option( 'page_for_posts' ); echo get_the_post_thumbnail($page_for_posts, 'large'); ?> But, somehow it doesn't :( Do I need to add this code in the loop or something? Any ideas? Thanks, Josh
I feel like such an idiot!! I was trouble-shooting this last night and I guess I removed the featured image for the news page...so, of course, the image wasn't showing up! I added the featured image and the following code: <?php if(is_home()) { ?> <?php $page_for_posts = get_option( 'page_for_posts' ); echo get_the_post_thumbnail($page_for_posts, 'large'); ?> <?php } ?> Now, everything works as expected (Note: cross-posted from, and issue resolved in, the wordpress.org support forums.)
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "posts, theme development, post thumbnails" }
Google adsense stats plugin? Does anyone know if there's a WP plugin that shows you stats about your ads (like clicks, earnings, etc) ? I've been looking around and most plugins I've found only let's you manage the actual ad code. I found this one but it doesn't work. Thanks in advance!
Probably Wordpress Ad-Manager plugin will help you. Pay attention that the plugin is not free, but it provides information that you need and makes even more.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "plugins, dashboard, adsense, google" }
How to translate "$before" with get text in get_the_term_list? How can I make $before (Books:) a translateable string <?php echo get_the_term_list( $post->ID, 'book', 'Books: ',', ', ' ', '' ); ?> with this method?: <?php the_content(__('Read more...', "ft")); ?>
Use the **`__()`** function, just as you see in the `the_content()` example: <?php echo get_the_term_list( // ID $post->ID, // taxonomy 'book', // Before __( 'Books: ', 'ft' ), // Separator, see __( ', ' ), // After ' ', // Looks like you've added an extra parameter? '' ); ?> Note 1: ~~I split the word "Books" from the part of the string that (probably) shouldn't need to be translated - i.e. the colon and space.); the two parts of the parameter are concatenated.~~ ( _Ed: Per @Toscho's suggestion, I changed this_ ) Note 2: Looks like you've added an extra parameter to your call to `get_the_term_list()`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "translation, query string, xgettext" }
Why load_textdomain work but not load_plugin_textdomain? In my plugin's `init` function load_textdomain( 'myplugin', ABS_PATH_TO_MO_FILE ); // OK load_plugin_textdomain( 'myplugin', false, ABS_PATH_TO_LANGS_DIR); // No effect echo( __('Test', 'myplugin') ); In the code above, the load_textdomain works, but not load_plugin_textdomain, any idea?
Looking at the source `load_plugin_textdomain` takes three arguments: load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false ) It seems you are passing the absolute path to your language domain, as a relative path. Try: load_plugin_textdomain( 'myplugin', ABS_PATH_TO_LANGS_DIR);
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugins, plugin development, multi language, localization, language" }
Identify current wordpress theme I want a theme very similar to these two websites. I am a newbie to wordpress and am trying to understand what theme is it. It looks like both the sites have a similar theme. Is there a way I can fin out what is the theme that they are using? Any help would be appreciated. <
In your browser * select "View page source" * search for `style.css` * you'll find something like this: ` * there you already have the theme name, and if you open the URL you also gonna see at the beginning of the stylesheet a header with all the information about the theme and its author
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, theme development, themes" }
How to only publish posts with image in it I use a standard loop in my index.php and that shows all the posts beeing posted. What i'm looking for is a code that only shows the posts that have image(s) in it. With other words: i only want to show posts that have images in content in my loop.
I found and modified a chunk of code found here: < <?php while ( have_posts() ) : the_post(); $content = $post->post_content; $searchimages = '~<img [^>]* />~'; preg_match_all( $searchimages, $content, $pics ); $iNumberOfPics = count($pics[0]); if ( $iNumberOfPics > 0 ) { //your loop content goes here } endwhile; ?> I think this just looks for images entered in the rich text editor - if you want to check for featured images as well you'll likely have to add something. Check out `has_post_thumbnail`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, functions, images, loop, query posts" }
What's the handle for media.js? I want to use `wp_enqueue_script` to load `media.js` from frond end. I use Win Grep searching through the whole WP dir, couldn't find which handle this `media.js` was registered. in this `media.js` , there's a function `findpost.open` , that's what I need. Could anybody tell the handle?
The handle is `media`. View in source, line 403.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "javascript" }
Multisite WPLANG won't save I have a multisite workpress install (v 3.3.2). I'm trying to save the WPLANG field but nothing happens. I get the confirmation message "Site options updated", but the field is still blank. And when I query it with get_locale, it get the default 'en_US'. I've tried entering in: ja_JP 'ja_JP' "ja_JP" ja-JP 'ja-JP' "ja-JP" Thanks in advance!
To set a specific language in a multi-site the language files must be available in the language directory, usually in `wp-content/languages`. So if you want to set the language to `ja_JP` a file `ja_JP.mo` must exist there. You can get the language files from the SVN repository.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "multisite, multi language, localization, l10n" }
Use the page slug in a WP_Query? I'm doing some custom loops that I initialize with a query like this $the_query = new WP_Query('page_id=266'); It works fine. It's just I'ld to call my page with its slug and not its ID. Would it be possible ?
use `pagename=` to query by slug. See WP_Query for full list of valid arguments.
stackexchange-wordpress
{ "answer_score": 11, "question_score": 8, "tags": "wp query, slug" }
How can i create a newsletter for my wp blog? I own a blog and finally wants that my users should be able to get a weekly newsletter on the blog. Basically I am a new user of wordpress and not sure how i can do that. I got some material on internet how can i create a weekly newsletter but all are paid services and right now I wont be able to afford them. Can anyone help me out???
I would personally advise against running the newsletter from your server directly as their can be issues with delivery rates and mails being flagged as spam. Instead < have a free user plan that would be suitable for you; as they are a premium service provider you can feel more confident that your email delivery rates are going to be higher than the aforementioned. There is also a MailChimp plugin for WordPress that helps you integrate with their service.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, plugin recommendation, newsletter" }
How to get the theme index.php listed in appearance editor When viewing my theme files via "Appearance > Editor", the index.php file that's listed there is an index.php that's inside a subfolder of my theme directory, not the main index.php file that resides in the root of my theme folder. How can I tell WP to list my theme's index.php there?
I've found the problem. I had placed an empty index.php file into a subdirectory folder under my main theme folder to prevent directory browsing on that folder. The presence of this index.php was causing the wordpress file editor to assume it was the default index.php for my theme. _Renaming that file to **home.php** has resolved the problem_ and the file editor now properly loads my theme's index.php file as the " **Main Index Template** "
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development" }
How to add custom function to pluggable.php I am working on a WP plugin and I want to add a custom function to pluggable.php (located in /wp-includes). I am calling that function from admin.php (located in /wp-admin) eg. Consider the function `auth_redirect` which is called from admin.php. `auth_redirect` is the function defined in pluggable.php which checks for logged users, else it redirects them to login page. Similarly, I have my own custom function. So, is there any specific hook or filter which I must use to attach my function to pluggable.php. Currently, I am using `fwrite()` to add my custom function to pluggable.php. But, I guess this isn't the right way. So, can you suggest me the right way of inserting my custom function and calling it from admin.php Any help will be appreciated.
You should not and do not need to write to `pluggable.php` (or any other core WordPress file). You can override a pluggable function simply by defining it in your plug-in's files (or for themes, `functions.php`). These get loaded before `pluggable.php`, and so the function definition given in your plug-in file is used in preference to that in `pluggable.php`. You'll want to wrap you function definition inside a `function_exists` conditional: if( !function_exists('function_name') ){ function function_name(){ return 'Hello World'; } }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, plugin development, php, functions, pluggable" }
Custom Post Type permalink doesn't match post permalink I created a Custom Post Type for Games, but when I add it, the permalink is showing as < where my_games is the custom post type name and test-game is the post name. I have `'rewrite' => false,`, is there something else I should be doing? I want the permalink structure to be the same as regular posts, `/%category%/%postname%/` What do I need to change?
Your question has the answer right in it! > I have 'rewrite' => false,, is there something else I should be doing? From the Codex: > To prevent rewrites, set to false. By setting that to false, you're preventing the default behavior that you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, permalinks" }
How do I add indexes to Wordpress Database? I got a message from Hostgator about my account being suspended because of the load it put on their servers. This is about the fifth time this has happened. I am on a shared server. And they said it could be resolved by simply adding new indexes to the database or optimizing the database using other techniques. I have been using SQL queries and the "optimize" option in phpMyAdmin to optimize my database but that hasn't helped. I have also installed Super Cache as recommended by them but this hasn't helped either. Now, I want to try adding indexes to the database. How do I do this? Does anybody know how to do this please? It's urgent. Thanks.
The WordPress database is already indexed. See this codex article for a detailed list of indexes per table: < And even if it weren't, you'd need to know what queries are being run in order to effectively add indexes. Meaning, there would be no quick fix--you'd have to learn how indexing works, figure out what queries are performing poorly, and go from there. If you really do have slow query issues, it most likely has to do with a poorly written plugin or theme file you're using. Try disabling all plugins and switching to the default theme, to see how it affects performance. If your site is still too taxing for your shared host (with a default theme and no plugins running), you need to move hosts.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "database, sql, server load" }
How to get the term description in a taxonomy term archive query? I'm creating a template for a custom taxonomy for my theme. At the beginning of the page, **before the loop** that lists all the posts associated to a **term** of that taxonomy, I want to output the **description** for that term. I have tried with term_description() but it doesn't work, no output... get_the_terms and other functions I know are meant to work within a loop for individual posts (with post->ID)... Anyone has a clue on how to achieve this? many thanks
The `term_description()` function returns the description rather than echoing or printing it. To fix the issue, use: echo term_description();
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, loop, taxonomy, query, terms" }
Check if term is in a taxonomy? Is there a function that does something like: is_in_taxonomy($term, $taxonomy) Where it returns true if `$taxonomy` has that `$term`. ???? Thanks!
You're probably looking for **`term_exists()`**: <?php term_exists( $term, $taxonomy, $parent ); ?> `$term` is **required** (obviously). Both `$taxonomy` and `$parent` are optional, but if you want to determine if a _specific_ taxonomy has a given term, just pass the registered taxonomy name via the `$taxonomy` parameter.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom taxonomy, functions, terms" }
Check to see if specific loop has less than certain amount of posts I'm looking for a way to check how many posts are returned by a specific loop. So if I have a loop like this.. <?php $featured_post_id = get_the_ID(); global $post; $args = array('cat' => '9', 'posts_per_page' => 5, 'post__not_in' => array($featured_post_id) ); $my_query = new WP_Query($args); if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); ?> And if this loop returns less than 5 posts then I want to show something. In my situation I'd be showing another loop to add more results.
Try this: if ($my_query->post_count < $min_posts) { // Do Something. } Good luck! Hope that helps.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, loop, conditional content" }
How can I list Custom Post Types created with the Types plugin under categories? I am using the Types plugin and have ticked _Categories_ under the **Registered taxonomies that will be used with this post type** section. However, no categories seem to appear. Has anyone encountered this problem before? Any advice appreciated.
By default, category and tag archives only list Posts in that category. So, despite the UI appearing on the backend, the posts don't show up in the archives. Luckily this isn't too hard to solve. Look at this support thread and this answer in particular. It has resolved this issue for me in the past. Make sure not to use the first few code snippets in the thread as they interfere with menus. You may also want to look into Justin Tadlock's post: "Showing custom post types on your home/blog page".
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, categories, plugin types" }
How do I get the author's page url from their ID? What is the best way to get the author's page url, so < from their ID number?
<
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "php, functions, urls, author" }
How to get a feed for post type 'page'? I'm trying to get a feed for pages and a separate feed for posts. The feed for posts works perfect as it is. I just want a separate one but i have tried all the plugins and searched for about a week straight and still could not find a solution Is it possible to take feed-rss2.php and duplicate it to change the code to include pages instead of posts and call it by `?feed=my_custom_feed`? EDIT BELOW: < This is the script that I am using get the `<link>` tag from the item RSS. I want the pages to have an RSS feed unless anyone knows a different way of doing it without RSS. But the script above rotates the page every 30 seconds.
Feeds for post types are called with `feed/?post_type=POSTTYPE`. For no obvious reasons this doesn't work for the post type `page` – you get the posts instead. But there is a filter to fix that: `'pre_get_posts'`. Let's use it: add_action( 'pre_get_posts', 't5_pages_in_feed' ); /** * Set post type to 'page' if it was requested. * * @param object $query * @return void */ function t5_pages_in_feed( &$query ) { if ( isset ( $_GET['post_type'] ) && $_GET['post_type'] === 'page' && is_feed() ) { $query->set( 'post_type', 'page' ); } } Now you get the page feed at `/feed/?post_type=page`. Here is a plugin for that: T5 Page Feed
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "pages, rss, feed" }
My title won't update No matter how many times I go into settings, and update my website title, it remains the same. And does not update? I've tried clearing my cache, uninstalling my old theme, searched through source files, and CANNOT figure out why - my title just won't update. Any suggestions?
It looks like you can't update your low accept rate either. Anyways, have you tried checking your theme's header.php file? What is the value between the title tags? Are you using any third party plugins for SEO like Wordpress SEO by Yoast? Try adding this between the title tags: `<?php wp_title("",true); ?>` You will also run into the issue of not having a page title if you are using a custom page as your homepage, the Wordpress Codex entry here for Wp_Title suggests this bit of code if that's the case: `<title><?php bloginfo('name'); ?> | <?php is_home() ? bloginfo('description') : wp_title(''); ?></title>`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme options" }
Sub Domain's Pages return 404 Need some help, I created these websites The main site is working fine, but the pages of the those subdomains are not working. it always returns 404, you can try visiting those sites and click on any posts or pages..
You can always delete the .htaccess for each root directory, then visit each domain.com/wp-login.php then visit: Dashboard -> Settings -> Permalinks & save changes. (Automatically generates a fresh .htaccess) OR login to phpmyadmin for each domain, check out the database... options table... verify the "siteurl", and "home" columns. make sure they match the respective domains. OR Check the DNS zone template. Could very well be possible DNS conflicts.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "404 error, google xml sitemaps" }
Help in query for list links How to make one query for display a list of links like this: Date 05/20/2012 Category - Link Category - Link Category - Link Category - Link Category - Link Date 05/19/2012 Category - Link Category - Link Category - Link Category - Link Category - Link ....
Try it like this: $dates = array(); // declare an array to hold dates echo '<ul>'; if (have_posts()) : while (have_posts()) : the_post(); $thisday = get_the_time('m/d/Y'); // this post's date if (!in_array($thisday,$dates)) { // check if it's in the array echo '<h5>Date '.$thisday.'</h5>'; // if not, print header with date $dates[] = $thisday; // and store it } echo '<li>'; the_category(); echo '</li>'; endwhile; endif; echo '</ul>';
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, query posts" }
Plugin suggestion: Find broken links I recently changed a few categories, so I know I have a bunch of broken links now. Instead of spending hours going through previous posts and fix them manually, I want to use a plugin that can do that for me. My friend Google told me about the "Broken Link Checker" plugin which seems to be quite popular, but for whatever reason it doesn't work for me not matter what I try. I tried to find another similar plugin, but thus far without success. Do you know of any other plugins that basically do the same as the "Broken Link Checker", but might work for my installation? Thanks a lot in advance.
Try WP Link Validator - Detect Broken Links plugin. Looks like it should help you. Pay attention that this plugin is not free.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin recommendation" }
I want to remove the links from the term list returned by get_the_term_list I want to keep this category title on my pages, but I don't want it to be a link. <?php echo get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' '); ?> Can anyone help? Thanks
You could use `get_the_terms()` and `wp_sprintf_l()`: function wpse_52878_term_list( $args = array() ) { $default = array ( 'id' => get_the_ID(), 'taxonomy' => 'post_tag', 'before' => '', 'after' => '', ); $options = array_merge( $default, $args ); $terms = get_the_terms( $options['id'], $options['taxonomy'] ); $list = array(); foreach ( $terms as $term ) { $list[] = $term->name; } return $options['before'] . wp_sprintf_l( '%l', $list ) . $options['after']; } echo wpse_52878_term_list( array ( 'id' => get_the_ID(), 'taxonomy' => 'portfolio_cats' ) ); * * * Another option: echo wp_strip_all_tags( get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' ') );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php, taxonomy, links, code" }
echo term name outside the loop, using term slug I have a strange question... I have my term as a variable... $mailer = 'may-2012-newsletter'; And I'm trying to echo on my page the Name of my term, using the variable above. But this is not in a loop. My term name is: **May 2012 Newsletter** But I'm trying to echo this from using my term slug: **may-2012-newsletter** This term is grouped in my taxonomy called: **mailers** I've tried this below but this doesn't work? I think I'm totally off track. <title><?php echo get_term_by( 'name', $mailer, 'mailers'); ?></title> Any help would be awesome thanks. Josh
You can use get_term_by to get the term object if you know the slug and then just echo out the name ex: $by = 'slug'; $slug = 'may-2012-newsletter'; $taxonomy = 'mailers'; $term = get_term_by( $by, $slug, $taxonomy); echo $term->name;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "taxonomy, terms" }
get_post_meta returns 0 I am trying to get metadata for a post (of custom post type). I had a look in the database, and the table "wp_postmeta" holds a row with "post_id" = 65, "meta_key" = "name_text" and "meta_value" = "Lars Åkerkvist". I am trying to fetch that value, Lars Åkerkvist, using get_post_meta as below get_post_meta(65,"name_text",true) But it always returns a 0. What am i doing wrong here?
Change `$single` back to `false`, e.g.: <?php $name_text = get_post_meta( 65, 'name_text' ); ?> Why? > If set to true then the function will return a single result, as a **string**. If false, or not set, then the function returns an **array** of the custom fields. This is not intuitive. For example, if you fetch a serialized array with this method you want $single to be true to actually get an unserialized array back. If you pass in false, or leave it out, you will have an array of one, and the value at index 0 will be the serialized string. You want to return the **array** , and then use `$name_text[0]`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field" }
using custom fields on content.php file of my theme is there any error in following code? when i use following code in content.php file of my theme, then nothing is displayed on blog, it seems there is some error. and when i comment folowing code everything gets back to normal. <?php if (empty(get_custom_field_value("signature",""))) : ?> &mdash; <?php the_category( '<span>/</span>' ); ?> <?php endif; ?> here is `get_custom_field_value` function: function get_custom_field_value($szKey, $prefix = '', $bPrint = false) { global $post; $szValue = get_post_meta($post->ID, $szKey, true); if ( $bPrint == false ) return (empty($szValue) ? "" : $prefix . $szValue); else echo (empty($szValue) ? $szValue : $prefix . $szValue); }
`empty` will only take variables passed by reference. so `empty(some_function())` will never work. See the php docs for more information. <?php if (get_custom_field_value("signature","")) : ?> &mdash; <?php the_category( '<span>/</span>' ); ?> <?php endif; ?> You're better off just checking for the boolean, like above. The `get_custom_field_value` function already takes care of making sure you get something back. On a side note: you should prefix your function names. `get_custom_field_value` is very generic. `yourtheme_get_custom_field_value` (replacing "yourtheme" with the theme name) has less of a chance of conflicting with other function names.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field" }
How to create a child/addon plugin This is a spin of: how to create child WordPress plugin I am using a plugin that I use and like a lot, but there is a feature that I need and it seems like the author is busy with life. I am a PHP developer so I could hard code my feature to his plugin, but this way on the next update I will not be able to update without loosing my changes. I have seen that there are some plugins out there that are addons/child to other plugins and they will not work unless you have the main/mother plugin installed. So my question is what is best to do in this situation? What steps I should take to make sure that after updating the main plugin my child plugin will still work?
Personally I'd either write my own plugin with a if plugin x exists clause or just edit it and send the code off to the developer saying "I have added a feature to your plugin, hope you like it" kinda deal. Realistically though, in my own site I just edit the code and be done with it cause I know that plugin will be there cause I put it there and won't remove it. If he is too busy to respond to feature requests he is probably too busy to update his plugin so that shouldn't be a problem, just be sure to remember that next time he does update though.
stackexchange-wordpress
{ "answer_score": -3, "question_score": 2, "tags": "plugins, plugin development" }
Shortcode for output of wp_get_archives displays at top of post Why does the output of this function // One Recent Post function most_recent_post_shortcode() { return wp_get_archives( 'type=postbypost&limit=1&format=custom'); } add_shortcode( 'recent-post', 'most_recent_post_shortcode' ); and shortcode `[recent-post]` show the output at the top of a post rather than in the body of the post where the shortcode is? Is there a better way to use a shortcode and wp_get_archives (or other function) to display the title and link of a recent post? It seems to have something to do with this question: The result of a shortcode appear BEFORE page content
The default of the `echo` argument is `true` for `wp_get_archives()`. I think this would fix it: // One Recent Post function most_recent_post_shortcode() { return wp_get_archives( 'type=postbypost&limit=1&format=custom&echo=0'); } add_shortcode( 'recent-post', 'most_recent_post_shortcode' ); UPDATE: Previously: echo=false Now: echo=0
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "shortcode, wp get archives" }
Single Image Gallery Post I'm trying to edit my new theme and I got the following comments: 1. Single image gallery post: image shifted in left side with footer 2. Need next and previous image gallery link on single image gallery post. I know how to create a gallery post with many thumbnails, but how do I create a single gallery post in order to simulate the above to comments?
Read Theme Unit Test and import the test data (including images!) into a new blog. You will get everything you need to test. There is a gallery post included ( _Images Test_ ), and if you click on an image you get an attachment page for this gallery image. Here is a screen shot from TwentyEleven: !enter image description here See the links in the upper right corner? Look into the source code of TwentyEleven to understand how they are implemented. Use `previous_image_link()` and `next_image_link()`. <span class="nav-previous"><?php previous_image_link( false, __( '&larr; Previous' , 'twentyeleven' ) ); ?></span> <span class="nav-next"><?php next_image_link( false, __( 'Next &rarr;' , 'twentyeleven' ) ); ?></span>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "gallery" }
How can I add more code to this? <?php $my_query = new WP_Query( "cat=11&posts_per_page=1" ); if ( $my_query->have_posts() ) { while ( $my_query->have_posts() ) { $my_query->the_post(); the_excerpt(); } } wp_reset_postdata(); ?> Where it says the_excerpt, how come I am unable to add other code alongside this? I'm guessing it's because it's still within the PHP tag, but I am unsure of how to seperate the two. Is there a way to make a section where the_excerpt is so that I may add additional code? I'm trying to add: <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="postdetails"> Written by <strong><?php the_author(); ?></strong> <?php the_time ('j F, Y'); ?> Posted in: <strong><?php the_category(', '); ?></strong> <?php the_tags(); ?> </div> and THEN the excerpt Thank you
To insert new code you need to break php code and past your new html+/-php code. But pay attention that after passing all will have correct syntax. Your question should be made like this: <?php $my_query = new WP_Query( "cat=11&posts_per_page=1" ); if ( $my_query->have_posts() ) { while ( $my_query->have_posts() ) { $my_query->the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="postdetails"> Written by <strong><?php the_author(); ?></strong> <?php the_time ('j F, Y'); ?> Posted in: <strong><?php the_category(', '); ?></strong> <?php the_tags(); ?> </div> <?php the_excerpt(); } } wp_reset_postdata(); ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, customization, query, content, excerpt" }
Transferring standalone wordpress blog to the one under **.wordpress.com I have a blog that is working on wordpress installation and now I want to transfer it to the my new blog under WordPress.com domain name. Is it possible to carry all the content to new WordPress blog?
If you're dealing with a WordPress.com hosted site, then you don't have direct DB access. You'll need to export out your content, and import it into the new site using the options in the WP admin area. You also may not be able to use the same theme. WordPress.com hosted sites have way more restrictions than other hosting options.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wordpress.com hosting, migration" }
List posts by category exclude current post I'm trying to get a list of posts from one category, echo the title and the permalink of all posts on that category but exclude the permalink and the post name IF the current post is on that list. It will be displayed on single.php after or inside the loop Anyone knows if it is possible, if so how? Thanks in advance <?php query_posts('category_name=MyCatName&showposts=-1'); ?> <?php while (have_posts()) : the_post(); ?> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> <?php endwhile; ?>
First off, note that, since your custom loop is a secondary loop/query, you should use the `WP_Query` class instead of `query_posts()`. Read why. That being said, /* main post's ID, the below line must be inside the main loop */ $exclude = get_the_ID(); /* alternatively to the above, this would work outside the main loop */ global $wp_query; $exclude = $wp_query->post->ID; /* secondary query using WP_Query */ $args = array( 'category_name' => 'MyCatName', // note: this is the slug, not name! 'posts_per_page' => -1 // note: showposts is deprecated! ); $your_query = new WP_Query( $args ); /* loop */ echo '<ul>'; while( $your_query->have_posts() ) : $your_query->the_post(); if( $exclude != get_the_ID() ) { echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; } endwhile; echo '</ul>'; that'll do.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "categories, query posts, exclude" }
Add $more_link_text parameter to the_excerpt() this `filter` is on the Wordpress Codex … add_filter('excerpt_more', 'new_excerpt_more'); function new_excerpt_more($more) { global $post; return '<a class="moretag" href="'. get_permalink($post->ID) . '"> &hellip; </a>'; } This works perfect, however I wonder if it is also possible to create a filter that extends `the_excerpt()` with the same parameter like `the_content()` where it is possible to set the "more-link-text" as parameter? So I wonder how I can achieve this … `the_excerpt('custom more link')`` This would be especially useful for me because I have multiple custom-post-types where I always use `the_excerpt()` as teasers. Since those custom-post-types have various contexts and meanings it would be nice to have different "more-links" at the end … Is this somehow possible? Thank you in advance!
You can use `get_post_type` add_filter('excerpt_more', 'new_excerpt_more'); function new_excerpt_more($more) { global $post; $post_type = get_post_type($post); switch( $post_type ): case 'event': $teaser = '<a class="moretag" href="'. get_permalink($post->ID) . '"> More events </a>'; break; case 'post': $teaser = '<a class="moretag" href="'. get_permalink($post->ID) . '"> &hellip; </a>'; break; default $teaser = ''; endswitch; return $teaser; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "custom post types, filters, the content, excerpt" }
Allow admin login at /admin I am interested in: 1. how can we change the default login url `/wp-admin` to `/login` 2. how can we add another url for login so that both `/wp-admin` and `/login` would work I tried to use a custom filter and .htaccess as in the following example but without success. functions.php add_filter('admin_url', 'my_new_admin_url'); function my_new_admin_url() { return '/login/'; } .htaccess Redirect permanent /wp-admin/ /login/
another option - redirect `/admin/` to `wp-login.php` with a `parse_query` action hook: function wpa53048_parse_query( $query ){ if( $query->query_vars['pagename'] == 'admin' ): wp_redirect( wp_login_url() ); exit; endif; } add_action( 'parse_query', 'wpa53048_parse_query' ); **EDIT** Well the above apparently only works with certain permalink structures. Here's another method hooked to `parse_request`: function wpa53048_parse_request( $query ){ if( $query->request == 'admin' ): wp_redirect( wp_login_url() ); exit; endif; } add_action( 'parse_request', 'wpa53048_parse_request' );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "admin, urls, htaccess" }
Removing Line Break Tags from a Page I am running the latest version of Wordpress on the Genesis Framework with the AgentPress theme. There is an annoying four line gap between the page title and the Wordpress Post Tab widget that I have installed. Using Firebug, I discovered that the gap is caused by four line break tags < br > , which seem to be automatically generated since I did not include them in the text editor. !enter image description here
You can hide `<br />` elements with CSS using `display:none;` ofcourse you might want to try going into your post editor and removing any blank lines. WordPress converts line breaks into tags for you automatically when the content is rendered using a function like `the_content()`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "html, formatting" }
Export all posts as individual plain txt files I wish to export all of my posts as individual plain text files. So, the format may be something like: title.txt Title: title Pub date: date Category: cat Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et Is this possible? Is there a plugin or workaround to do this? Thanks.
Try this (you may need to bootstrap WP by loading `wp-load.php`, depending on where you put this code). $args = array( 'post_type' => 'post', 'post_status' => 'publish', //'posts_per_page' => -1 //uncomment this to get all posts ); $query = new WP_Query($args); while ( $query->have_posts() ) : $query->the_post(); $f = fopen(get_the_title() . '.txt', 'w'); $content = 'Title: ' . get_the_title() . PHP_EOL; $content .= 'Pub date: ' . get_the_date() . PHP_EOL; $content .= 'Category: '; foreach (get_the_category() as $cat) { $content .= $cat->cat_name . ', '; } $content .= PHP_EOL . PHP_EOL; $content .= get_the_content(); fwrite($f, $content); fclose($f); endwhile; Keep in mind, if two posts have the same title, you'll only get one text file.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 6, "tags": "export, text" }
Ability to leave comments broken At some point, my readers were able to add comments on both the main (front) page of my site and from the post pages as well. Without any obvious change to the configuration of my site, the comment form has disappeared from my article page and, when I click the link from the front page to "add a comment," I'm brought to the article page with no comment form. You can see the behavior at <
Verify comments are enabled by default: Dashboard -> Settings -> Discussion -> Default article settings. Verify comments are enabled for all posts/pages: Dashboard -> Posts -> Check all posts. -> Bulk actions (Edit) -> enable comments. Same thing for pages. Verify your template files. Do you still have a comments.php file?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "comments" }
Login in Wordpress using external database data I have a WP site and also have a external DB (means not WP DB) with users. The insertion process at that table uses the same algorithm as WP uses. What I'm need to do here is login in WP but using this external DB which is in the same host by the way. I check this links < and < and for the first is not what I'm want but for the second one is not compatible with WP 3+ and I'm using 3.3.1, any suggestion or docs or something else?
You can override the core wp_authenticate function. You would need to create a custom plugin and declare a new version of wp_authenticate. The function accepts a username and a password and returns a WP $user object. wp_authenticate is a 'pluggable' function and it is found in the wp-includes/pluggable.php file.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "database, login" }
Does Wordpress Loop have a function like Shopify's cycle? Shopify's Cycle lets you alternate between things within a loop. Here's my example: <div class="{% cycle 'first', 'second', 'third' %}"> {% include 'product-grid-item' %} </div> My question, is there anything like this for Wordpress? I'd love to be able to cycle through some kind of setting - such as class names - as each item in my loop is printed.
Short answer, no. But that is a pretty cool feature! To so something similar in WordPress, you'd need to code some kind of iterator in PHP and have it do the logic for you. For example: $classes = array( 'first', 'second', 'third' ); $iteration = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); $iteration = $iteration >= count($classes) ? 0 : $iteration; $class = $classes[$iteration]; ?> <div class="<?php echo $class; ?>"> <!-- Whatever other stuff you need to do --> </div> <?php $iteration++; endwhile; endif;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "loop" }
What characters are allowed as a shortcode tag and how should they be sanitized? I am working on a plugin where the user can define shortcode tags himself. What would you suggest to allow in there? My thought is only allow ascii characters. So how do I sanitize? `strip_tags` and then regex to allow only `a-z, 0-9` or is there a better solution? Does WordPress have filter for that? Could I maybe use the filter WordPress uses for slugs? thanks for the answers i will just do this, if there must be one ascii char anyway then i just require three. foreach ( $shortcodes as $key => $var ) { $var = preg_replace('/[^a-z0-9_]/', '', $var ); // strip away everything except a-z,0-9 underscore if ( strlen($var) < 3 ) continue; // if less then 3 chars AFTER the strip don't save
You can use almost every character. Just the character `/` is dangerous. Do not allow it. WordPress is using `preg_quote` to escape the shortcode name, but it doesn't include its own regex delimiter `/` when doing that. So the shortcode will not be properly escaped and you get a PHP warning. Besides that, there are just two basic rules for a shortcode name: 1. It should be at least two characters long. 2. It should contain at least one US-ASCII character (`a-z0-9`). So this works: foreach ( array ( '.-o', ']b', 'äoß', 'o"o', "o'o", 'm' ) as $shortcode ) { add_shortcode( $shortcode, 't5_crazy_shortcode_handler' ); } function t5_crazy_shortcode_handler( $attrs = array(), $content = NULL, $shortcode ) { return "<pre>\$shortcode: $shortcode\n\n\$attrs\n" . htmlspecialchars( print_r( $attrs, TRUE ) ) . "\n\n\$content" . htmlspecialchars( print_r( $content, TRUE ) ) . '</pre>'; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 5, "tags": "plugins, filters, shortcode" }
Adding a unique class to wp_nav_menu How would I go about adding a unique class to the direct child li elements of the main parent ul element generated with wp_nav_menu? <nav id="access" role="navigation"> <div class="menu-main-container"> <ul id="menu-main" class="menu"> <li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-30"><a href=" <ul class="sub-menu"> <li id="menu-item-50" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-50"><a href=" <li id="menu-item-49" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-49"><a href=" </ul> </li> </ul> </div> </nav> I'd like to add the class `menu_element` to `li id="menu-item-30"` and every child li of the parent ul after. Is this possible? Thanks in advance!
Check out the section titled Adding Conditional Classes to Menu Items on the `wp_nav_menu` Codex page. This should give you a pretty good overview for adding classes to menu items using the `nav_menu_css_class` filter. For what you asked to do, which is add `menu_element` to the class attribute for both the menu item with ID 30, and the menu items listed after it, you could do something like this in your theme's `functions.php` file: function menu_element_class($classes, $item){ if($item->ID == 30 || $item->menu_item_parent == 30) { $classes[] = "menu_element"; } return $classes; } add_filter('nav_menu_css_class' , 'menu_element_class' , 10 , 2); This just checks to see if the menu item has an ID of 30, or has a menu_item_parent of 30, and adds "menu_element" to the classes array. Of course, you can change the `if` statement to check for whatever conditions you'd like before adding the class.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, menus" }
Wordpress - Admin Manage Posts - Multiple Filters by Parent Category Lets say I have the following Categories in Wordpress: Product Category - Cat A - Cat B - Cat C Service Type - Service A - Service B - Service C On the Manage Posts page on the Admin side, I want to have 2 drop down filters for both Product Category, and Service Type, so I can filter by both on the backend. How can I do this?
I'd say it's quite a huge task to split the default taxonomy in two dropdowns. Maybe some wizard stumbles upon your question and enlighten us... The biggest problem I see is the split itself, because you can modify the query `&cat=1` to `&cat=1,25` so as to list two categories (by their id's). What I suggest is creating a custom taxonomy for dealing with either Products or Services. And leave the other in the default categories. And then apply the solution I linked in the comments to the question. This way is easy to have two dropdowns and do the custom filtering you're looking for. Just tested and it works. Hope this helps.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "posts, categories" }
Child theme grabbing wrong location fo parent theme files I purchased a Wordpress theme this week, and to keep my changes separate from the original theme, I created a child theme for it. Right now it's just a barebones child theme, the style.css file and screenshot. The parent theme has several CSS and jQuery scripts that it includes. The problem however is that the child theme looks for these files in the child theme directory, rather than the parent. For example if I am using the parent theme the location would be: ParentTheme/js/jquery.easing.js However in the child theme, it looks for the files here: ChildTheme/js/jquery.easing.js Rather than the parent theme like I would assume. I tried copying the CSS and JS folders, but that didn't work either. Am I doing something wrong? How would I use a child theme for a parent theme that has several CSS and JS files that are needed? You can take a look for yourself here if you would like: <
As this is a commercial Theme, you really need to contact the developer for support. That said: the Theme appears to be mis-using **`get_stylesheet_directory_uri()`**, when it _should_ be using **`get_template_directory_uri()`**.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "child theme" }
Ajax call to transients If I make an ajax call to a Wordpress transient, is the transient value taken from memory on the server or is a call to the database made? I'm not using any caching plugins. My application is fetching a tag list. The frontend will display matching tags as the user types. I'm assuming that all transients are loaded when the page loads. And therefore that the transient is fetched from memory when the ajax call is made. Yes?
Without object caching plugins transients are stored using options API and, if set to expire, they have auto-load disabled. Meaning: 1. First request to transient needs to fetch it from database. 2. Subsequent requests will get data from memory. However note that "memory" here is memory space of **single specific page load**. It's not shared and not persistent. Ajax request performs new network request to site, loads new instance of WP core and does the stuff. It's quite heave operation, which is hard to optimize and it's performance impact overall makes transient API overhead irrelevantly small.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "transient" }
IE and WordPress I'm developing a WordPress based website. Using latest version of WordPress and Genesis theme. I've to use a seperate stylesheet for IE, how can I add that? Sorry for this silly question, I'm new in web development :(
Well, add these lines to functions.php of your theme. add_action('wp_head','ie_only'); function ie_only(){ ?> <!--[if IE]> <link rel="stylesheet" type="text/css" href="<?php echo get_bloginfo('stylesheet_directory'); ?>/ie-only.css" /> <![endif]--> <?php } Now create a css file with this name (ie-only.css) and put that into your theme's directory.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "css" }
How can i maintain permalink structure and avoid a 404 error when loading external content? I created a page called Catalog and also a template called page-catalog.php. The url looks like this now: sitename.com/catalog So far so good, however i use some custom php stuff to list products from another database. So when i click on a brand in this page, i want to use an url like this: sitename.com/catalog/brands/brandname But obviously because the data is not coming from Wordpress, it gives me 404. Is it possible to use the same page-catalog.php file if the url has more parts? I could use an url like this: sitename.com/catalog/?brand=brandname But this solution is not so sep friendly.
You could use a WordPress rewrite (as opposed to mod-rewrite) to solve the issue. function createRewriteRules( $rules ){ $newrules = null; $newrules = array(); $newrules["catalog/?$"] = "index.php?page=xx"; $rules = $newrules + $rules; return $rules; } add_action('rewrite_rules_array', 'createRewriteRules'); You'll need to flush the rules: < Your page-catalog.php file could then sniff the original url and do some processing as required.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "url rewriting, database, urls, 404 error" }
Valid filenames for add_action's first parameter Some examples in WordPress' docs pass a filename to `add_action` rather than an action name. For example, add_action( 'load-post.php', 'callback' ); add_action( 'load-post-new.php', 'callback' ); What are the valid filenames for the first argument in `add_action`?
Just found my answer. Those aren't filenames but examples of the `load-(page)` action.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development, filters, actions" }
What is the "with_front" rewrite key? I have the following line in a register_post_type function: 'rewrite' => array('slug' => 'Newsletters', 'with_front' => false), I understand what the line does in general (adds "newsletters" to the slug) but I don't specifically understand what the 'with_front' part does. I have to admit, I don't really have a problem that needs solving, but I'm suddenly curious....
From the Codex ... > Should the permastruct be prepended with the front base. (example: if your permalink structure is `/blog/`, then your links will be: false->`/news/`, true->`/blog/news/`). Defaults to true
stackexchange-wordpress
{ "answer_score": 48, "question_score": 38, "tags": "functions" }
Issue with RSS Feed in Firefox and Safari The feed for a site ( shows fine in Google Chrome, but in Firefox and Safari it gives errors. I've tried clearing the cache, but that doesn't solve the issue. Any idea what could be causing the problem?
This isn't a WordPress issue. An RSS feed is an XML document created by your server for end users to consume updates or changes through an RSS reader. **_A web browser is not an RSS reader._** Every browser will handle an RSS feed differently - and they'll do even stranger things if they don't recognize it as XML. Often, Chrome will see the feed and render it as a regular XML document - Chrome includes special parsers that clean up and format the display of an XML document to make it easier to read. Firefox and Safari both see the feed and recognize that it's an RSS feed. Each of these browsers actually has a mini feed reader built in, so they'll try to parse the feed _as a feed_ and will display it very differently than Chrome. If you see errors, it's likely a problem with the markup or encoding that prevents the browser from recognizing the file right away. If you want to _really_ test your feed, use an actual reader (i.e. Google Reader).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "rss" }
Plugin to set all Posts in a certain Category to a certain Post Format I want to setup my WordPress so that whenever I create a post with the category "Tweet", my wordpress installation automatically changes the post format from post to aside. This will help me because I want to use my wordpress for posting longer than 140 tweets to my twitter feed. The posting to twitter has been setup and it works. The problem is that the Wordpress iOS app doesn't allow me to change the post format to Aside, so the only thing I can do is set the category of the post to "Tweet" and as soon as my wordpress receives it, it changes the post to aside. I found the plugin "Set Aside" but it lets me change the post formats for all posts of a certain category that have already been posted, not the ones that I will post in the future. Is this possible?
Try putting this plugin in your `wp-content/plugins` folder and then activate it: <?php /* Plugin Name: WPSE53245 - Set Tweet category posts as Aside Plugin URI: Description: Set Tweet category posts as Aside Version: 0.1 Author: Ashfame Author URI: */ add_action( 'save_post', 'wpse53235_set_post_format_aside' ); function wpse53235_set_post_format_aside( $postID ) { if ( has_post_format( 'aside', $postID ) || !has_term( 'tweet', 'category', $postID ) ) return; set_post_format( $postID, 'aside' ); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "plugins, categories, post formats, automation" }
WP_Query with custom post type ID This code isn't echoing out anything, even though I'm 100% positive $mixtape_id is set to an integer which corresponds to one of the posts within the 'mixtapes' custom post type $query = new WP_Query(array( 'post_type' => 'mixtapes', 'p' => (int)$mixtape_id, 'posts_per_page' => -1, 'orderby' => 'meta_value_num', 'meta_key' => 'track_number' )); while ( $query->have_posts() ) : $query->the_post(); ?> <track> <location>track1.mp3</location> <creator>Artist name</creator> <title>Track 1</title> </track> <?php endwhile; ?>
I fixed it by doing it a different way $query = new WP_Query(array( 'post_type' => 'tracks', 'posts_per_page' => -1, 'orderby' => 'meta_value_num', 'meta_key' => 'track_number', 'meta_query' => array( array( 'meta_key' => 'mixtape', 'meta_value' => (string)$mixtape_id ) ) ));
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, posts, theme development, loop, wp query" }
toolbar not visible on pages using front-page template My profile is set to show the WP toolbar when viewing the site, but on a page using the front-page.php template the toolbar space is reserved but its contents are not visible. What could be the reason for this?
I had not included `wp_footer()`. It seems the code for the toolbar is included with this call, and `wp_head()`. Modifying the Toolbar Reasons Why Your Toolbar May Not be Showing
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "admin menu, admin bar" }
Editing a list of several fields I need to edit a list of quotes. Every quote consists of a (short) text, author's name, author's title. What is the best way to create an editor of such data in WordPress? It seems that the simplest solution is to create a custom post type. Should the quote text become the title of a post? (It is not quite the title, logically.) If not with post types, then how? Note, that I need two lists of quotes (in two languages).
I would build a custom post type. Use the editor to hold the quote in the site's default language and create a new box to hold the translated version. A second meta box can hold the author's name and title. For the post title, just use something descriptive, so that you can find the post later on for editing. When you get to the template, just don't use `the_title()`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, lists" }
problem with add_size_image why if im add size like : add_image_size( 'featured1', 466, 316, false); add_image_size( 'featured2', 466, 260, false); the seconde size Does not generated What is the problem ?
Probably because your sizes both have the same width, and you have it set to "proportional crop", which won't necessarily crop to your _exact_ dimensions. (See the Codex) In all likelihood, it _is_ actually creating both images--but they're both the exact same size, so one overwrites the other :) Try changing the last param to "true". add_image_size( 'featured1', 466, 316, true); add_image_size( 'featured2', 466, 260, true);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images" }
what is name of this plugin used for photo gallery page i need to now what is name of this plugin that's used for image gallery page in this site
According to the document source, the site is loading scripts from the NextGen Gallery Plugin.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, gallery" }
Woocommerce - Add a product to cart programmatically via JS or PHP I am using the Woocommerce plugin to facilitate a small e-commerce part of a site and need to add products to its cart via some call or function rather than using its own 'add-to-cart' buttons. By this I basically mean send Woocommerce a SKU and quantity for example and have the cart update. sendToCart('123456', 55); etc I've looked through the documentation and can't seem to find a reference to this sort of thing. Can anyone suggest how I might achieve this?
OK so here's how I solved it in the end. A quick and dirty example, uses JQuery. <a id="buy" href="#">Buy this!</a> <script> $('#buy').click(function(e) { e.preventDefault(); addToCart(19); return false; }); function addToCart(p_id) { $.get('/wp/?post_type=product&add-to-cart=' + p_id, function() { // call back }); } </script> This just makes an AJAX GET request to the cart url /wp/?post_type=product&add-to-cart=[PRODUCT_ID]
stackexchange-wordpress
{ "answer_score": 37, "question_score": 38, "tags": "woocommerce offtopic" }
Output HTML only on individual post view I am looking for a way to output some html (javascript actually) on a post view only and not on a main page, tag, category view (where WP outputs several posts). E.g it would be output on this page blog.yourdomain.com/2012/05/some-post/ But not on blog.yourdomain.com/ blog.yourdomain.com/category/xxx/ blog.yourdomain.com/tag/yyy/ etc. **The HTML to be output is different for each post**
Eugene's answer was a little over complex for my needs so here's what I did (though +1 to Eugene as it got me looking in the right places) I first added **a custom field called singlePostHTML** to the posts that I wanted to add script to - put the script in the value. Wordpress - Using Custom Fields I then edited **single.php** (as this template is used only when you're only displaying a single post, rather than multiple posts on home page or archive/category/search views). Wordpress - template hierarchy And added the following <?php echo get_post_meta($post->ID, 'singlePostHTML',true); ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, posts, customization" }
Use get_posts() with 'post' and 'page' queries at the same time? I'm trying to grab all posts which are 'posts' and not in category '3' and '5' and which aren't 'pages'. Is this possible to do using one single `get_posts()`? Because I'm querying both actual posts and pages at the same time...
The **`get_posts()`** function only returns _one post type at a time_. So if you query for `'post_type' => 'post'`, _by default_ you won't get any Pages returned. This should work: <?php $wpse53292_posts = get_posts( array( 'post_type' => 'post', 'exclude' => array( 3, 5 ) ) ); ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages, get posts" }
Custom Post Type URL Rewriting? I setup a custom post type for my portfolio projects. The main URL for this is located at `/projects/` Now I've also setup my blog posts permalink to `/articles/*/` for the permalink structure. This means when I go to view a portfolio project the URL changes to `/articles/projects/project-name/` I know there must be a way to rewrite permalinks **only** for my projects custom post type. But I'm unfamiliar with the syntax in declaring the URL slug - would appreciate any help I can get!
When you register the custom post type, you have to specify that the rewrite rule shouldn't be prepended with the existing URL structure. In short, this means that this line in your `register_post_type` call: 'rewrite' => array('slug' => 'projects'), should turn into this: 'rewrite' => array('slug' => 'projects','with_front' => false), For more info, check out the `rewrite` argument from the codex entry on `register_post_type` _edit: just make sure that, after updating the code, you flush the rewrite rules by visiting Settings > Permalinks. Otherwise you'll still see the old links._
stackexchange-wordpress
{ "answer_score": 60, "question_score": 40, "tags": "custom post types, url rewriting" }
exclude categories from search results I have the following function, I need to exclude categories from it because it works across the site in several different places. How can I do that? // allCategories(): return an array of categories to browse in heirarchy public function allCategories() { $return = array(); if ($this->category) { $return = $this->catList($this->section->term_id); } return $return; } } Thank you in advance.
In case it helps someone else, this was a much easier fix than I thought. I simply added the category ids to exclude to the query_posts argument, e.g., `query_posts("s=$s&cat=-415,-504&posts_per_page=-1");`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, exclude" }