INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Taxonomy archive with same slug as custom post type? My head hurts... Here is what I have: Custom post type: Our People, slug => **our-people** Taxonomy: Job Title, slug => **job-title** I have an archive page for the Our People CPT at **domain.com/our-people**. I can easily have archive pages for the Job Title taxonomy terms at **domain.com/job-title/{term}** But I would like to have archive pages for the Job Title taxonomy terms under the our-people slug. Example: **domain.com/our-people/managers domain.com/our-people/crew** Where managers and crew are terms of the taxonomy Job Title, which is attached the the CPT Our People. Is there a way to do this? Setting the taxonomy and the CPT to the same slug obviously didn't work. Thank you.
You have two avenues: * Hardcode rewrite rules for those specific URLs * Abandon your quest and design a new URL structure What your asking for cannot be automated efficiently because it would mean 2 rewrite rules that are the same, but are mapped on to different things. The result being that either the post type slug would take precedence, or the job would take precedence, but only one. E.g. say we had the url our-people/example, is referring to the people 'example' or the job 'example'? Either WordPress will find the person named example, and 404 if it can't ( despite there being one under job. Or it will do it the other way around # My Recommendation Change your URL structure to be less confusing and make more sense by nesting them: example.com/our-people/johnsmith example.com/our-people/jobs/managers do this by setting the rewrite value when you register your jobs taxonomy ( it's okay to use a / )
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "custom post types, custom taxonomy, slug" }
Meta boxes not displayed, data isn't being saved As the title says, I have a problem in functions.php (I assume it's in there) which causes custom fields to not be displayed on the new/edit post page, and when I add the meta box myself and save the data by updating the post, the data disappears. However, if I save the data by clicking the Update button for the meta box itself (and do not click the post Update button), the data is saved and displayed properly. I have posted the code in functions.php here.
This has to do with auto saving. You need to check the following before saving your fields: if ( ! isset( $_POST['action'] ) || $_POST['action'] != 'editpost' || 'revision' == $post->post_type ) return;
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field, functions" }
Widget items disappearing if ( function_exists('register_sidebar') ) register_sidebar(array( "name" => "Top Widget Area", "id" => "topWidgetArea-$i", )); I just create a new sidebar with this. I'm displaying this sidebar in my `header.php` like this: <?php dynamic_sidebar( "Top Widget Area" ); ?> It's displaying no problem and I can put every widget to my sidebar in wp-admin's Appearance -> Widgets page. When I refresh this widgets page, all the widgets (which are in the Top Widget Area) are disappearing. I'll explain it with a video. Please check: <
Changing widget's ID from `topWidgetArea` to `top-widget-area` solved my problem. Widget ID must have hypen. I tried a lots of variations for ID (like `testtesttest`, `asdasdasd`, `widgetareaaa`) . I'm not sure, why .
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, widgets" }
What log files does a WordPress installation write to? When tracking down WordPress problems, I've had a hard time finding where WordPress sends errors to. Where does WordPress send errors by default? Are there multiple files that different kinds of errors are directed to? (I'm either a terribly ungifted Googler or WordPress's own documentation is hard to sort through.)
Where (or if) errors are logged is dependent on your php configuration. You can control some of this via your WordPress `wp-config.php file`. See Configure Error Logging in Editing wp-config.php.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 8, "tags": "errors" }
Automatically decrease font size for long words I am working on an e-commerce site in which post and product titles will need to be displayed in fairly narrow divs. I would like to set a specific font size for words which can naturally fit in the space provided, while instructing words which are too long for the parent object's width to scale down automatically, thus avoiding the need for hyphenation. It seems someone must have thought of a way to do this before but I have been unable to find any solutions on the web. The closest I've found to an answer is the BigText jQuery plugin, but this is really designed for situations where you can predict your own line breaks. Since my titles will be queried by Wordpress and inserted altogether into divs, this plugin would shrink my texts until every word could fit on one line, which is not what I'm looking for. Please let me know if you have any suggestions. Thanks so much your time! Best, Jonathan
I’ve done something similar taking the simple approach of adding a CSS class to titles based on their character count. That CSS class then decreases `letter-spacing` and/or `font-size`. // Count the characters, taking Unicode into account $chars = mb_strlen($post->post_title); // For every 10 characters after the first 20, add a size $size = max(0, ceil(($chars - 20) / 10)); // Generate the CSS class: x-long, xx-long, etc. $class = ($size) ? str_repeat('x', $size).'-long' : ''; // Output echo '<h1 class="'.$class.'">'.esc_html($post->post_title).'</h1>'; This approach is quite naive, though. It doesn’t take into account the actual character width as rendered by the font. For that, you’d need a JavaScript approach.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "jquery, css, javascript, formatting, text" }
Login from Mobile Phone I use the "Member Access" Plugin to restrict the content of my Blog to registered users only. This works from a PC with no problem. But if I want to login from my Android Phone the login page always displays no matter if I input correct credentials or not. I don't get logged in. I deactivated all other plugins and used the TwentyEleven Theme. How can I login from a mobile device?
I had to allow Cookies in my Android Phone Web Browser. After activating Cookies I could log in my Blog and got redirected to its main page.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "login, mobile" }
which action to hook to in order to perform post-publish action I have some functionality I've written in order to post the title and link for the post to twitter whenever a post is published. I'm wondering which wp function to hook this to? save_post has no real reference documentation. Basically I just want to run an action when a post is successfully published. Thanks very much.
You could hook into `publish_post` like the plugin Inform about Content does. But this hook is fired on updates to published posts too, this may result in many redundant tweets … Try `'draft_to_publish'` instead. It is called in `wp_transition_post_status()` and happens only one time. You get the `$post` object as argument. Prototype, not tested: add_action( 'draft_to_publish', 'wpse_55516_tweet_new_post' ); function wpse_55516_tweet_new_post( $post ) { if ( 'post' !== $post->post_type ) { return; } // Tweet it like a boss … }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, plugin development, php, admin" }
How to prefix post permalinks with /blog/ - without affecting custom post types? I have several custom post types, which are properly structured as `/%post_type%/%postname%/`, however I wish to have the same effect for regular blog entries: `/blog/%postname%/` If I prepend the permalink structure with `/blog/` it affects the custom post types as well, so currently my permalink structure is simply `/%postname%/` Which is the recommended way of doing this? I had a solution involving some rewrites, but the permalink shown in the post editor area does not reflect it.
Set the `'with_front'` parameter for the post type’s slug to `FALSE`: 'rewrite' => array ( 'slug' => 'posttypeslug', 'with_front' => FALSE ),
stackexchange-wordpress
{ "answer_score": 15, "question_score": 12, "tags": "custom post types, permalinks" }
Remove "Next Post" in nav_menu I am creating my custom navigation menu with background-images. The menu items have a title from the Page, and that title is displayed above my background image, which is not what I want because the image itself already contains the link text. /* menu items */ function nav_menu_items($classes, $item) { $classes[] = "item-". $item->attr_title; return $classes; } add_filter('nav_menu_css_class', 'nav_menu_items', 10,2); .item-myitem a { background: url(someimage); text-decoration: none; width: 20px; } However in the HTML it is displayed as (background-image is OK) <a title="myitem" href="someurl">Next Post</a> How do I remove that "Next Post"?
You can do that with CSS text-indent: `text-indent:-9000px;`. That way your text is still there for accessibility.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus" }
Why this plugin doesn't work with media upload page? I found this plugin very useful ajaxed-status It was created for post and page, and I want to apply it on media library. so I commented out the line `if (is_admin() /*&& ($pagenow=='edit.php' )*/)` and added this: add_filter ( "manage_upload_columns", array ($this, 'add_new_columns' ) ); add_action ( "manage_media_custom_column", array ($this, 'manage_columns' ), 0, 2 ); Then, I got the status column on Media Library list page, and I can click the status to make it change to new status. But, the change can't be saved. From Firebug, I can see the ajax response is correct. I hope the original author, @Bainternet , or other people, may help figure this out. * * * **update** I tried update_post_meta to save the $status as meta. It works. Just can't save it as post_status by wp_update_post.
I think I find the answer-- wp-include/post.php: if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) ) $post_status = 'inherit'; So, whatever status will be saved as "inherit".
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "ajax, attachments, post status" }
Is there an URL listing latest posts Currently my homepage is showing my lastest posts but I want to replace it with a page. I wish that all the posts could still be seen in a widget and by clicking on "news" in the menu. I already do that for custom types with ` which shows all my lastest items. Just by adding this URL to my main menu Is there the same URL already existing for posts?
As mentioned in the comments, you want to replace your home page with a static front page under Settings > Reading. Then you'll create a new page and set it as your posts page in the same setting. The slug of that new page then determines the URL of the posts page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "urls, homepage" }
Ajax for non-logged-in users I'm working on a plugin that captures some data from a non-logged-in user (such as a Like Button) and enters it into the database based on post_id. My plugin works fine for logged-in users but non-logged-in users produces a "-1" response in AJAX. I'm guessing this has to do with an authentication barrier for writing to the database but I'm looking for a way to work around that. Any ideas? EDIT: Here is the code: < I'm basing this off the Love-It AJAX plugin by Pippin. He says in the tutorial that this only works for logged-in users but I need to get this to work for non-logged-in users as well.
The `wp_ajax_{action}` hook only fires for logged in users. For logged-out users the action `wp_ajax_nopriv_{action}` is triggered on an ajax request - so you need to hook into that as well.
stackexchange-wordpress
{ "answer_score": 9, "question_score": 4, "tags": "ajax, authentication" }
Short_title character problem I am using this code to shorting the title: function short_title( $after = '', $length ) { $mytitle = get_the_title(); if( strlen( $mytitle ) > $length ) { $mytitle = substr( $mytitle, 0, $length ); echo $mytitle . $after; } else echo $mytitle; } and i call it with: <?php short_title( '...', 40 ); ?> The script works fine but i am having character problem. See the picture. Any idea how to solve it?
Use `mb_strlen()`, not `strlen()`. The same with `mb_substr()` and `substr()`: Your title contains multi-byte characters, but `strlen()` and `substr()` do not work on characters, they work on single bytes. For a improved function to shorten strings see this answer.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "functions, title" }
How to add class on Widget Title This is an example of register sidebar function from codex. My focus is on the `before_title` argument. What i want is to add a class to the title(`<h3>`). From my widget code or may be pass the class name from user input on widget area. <?php $args = array( 'name' => sprintf(__('Sidebar %d'), $i ), 'id' => 'sidebar-$i', 'description' => '', 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3>', 'after_title' => '</h3>' ); register_sidebar( $args ); ?> So, **How do i add classes dynamically on widget header?**
Two approaches: 1. **Don't bother** Just target `.widget.{dynamic-class} h3` instead 2. **Use`%2$s`** I don't know if this will work, but try: `'before_title' => '<h3 class="%2$s">'` But personally, I'd go with the former option. You've already got a unique class name; just leverage the element hierarchy to apply styles selectively.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "widgets" }
add image map script to post when i add this script to my post html editor : <div style="text-align:center; width:1100px; margin-left:auto; margin-right:auto;"> <img id="wordlmap" src=" usemap="#wordlmap" border="0" width="1100" height="489" alt="" /> <map id="wordlmap" name="wordlmap"> <area shape="rect" coords="845,267,929,324" href="/australia" alt="australia" title="australia"/> </map> </div> after updating post, i only get: <div style="text-align:center; width:1100px; margin-left:auto; margin-right:auto;"> <img id="wordlmap" src=" usemap="#wordlmap" border="0" width="1100" height="489" alt="" /> </div> can someone help me please, thanks in advance
The post content is filtered by kses, but you can extend the list of allowed tags. A search in the plugin directory for kses shows some useful results. Try Extend KSES, it seems to be exactly what you need (I haven’t tested it): > This plugin extends the HTML functionalify of the WordPress kses.php file, which states the allowable HTML that the post/page content editor will accept. > It allows the site administrator to check pre-defined HTML tags that can also be allowed via the editor. Tags include: `object`, `embed`, `param`, `iframe`, **`map`** and extensions have been added to the `div` and `img` tags.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "posts, editor" }
After a manual update, themes and plugins that were installed (and still in the directory) are not being seen The title pretty much says it all. The files and folders for my various themes and plugins are all intact in their proper path location under wp-content, but the WordPress install is not seeing them. Additionally, all of the pages within the site are loading a blank white pages (my assumption is that this is a result of the install not seeing any themes). I'm stumped...
No longer stumped. wp-content was owned by root. After running `chown -R apache:apache wp-content`, everything looks to be working correctly.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, themes, updates, fatal error" }
How to programmatically detect how many posts are displayed per page? Part of a custom post type that I am building needs to simulate page 1 of a category archive. How can I found out how many posts are displayed per page across the WordPress installation? (I assume it is in `wp_options` but I cannot find it.) Thank you!
The option is appropriately named `posts_per_page`. FYI you can see the value of options in your database by visiting `wp-admin/options.php`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, options" }
How do I ensure custom post type information is displayed in correct order? I would like to display some category archives below whatever the user has typed in on a custom post type. How do I make sure that the user's content displays above mine?
To achieve this, I used `add_filter( 'the_content', 'myFunction' );` Then in my function, I echoed `the_content()` to display the content the user typed in and then echoed the other content I needed.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types" }
Upgrade to 3.4 error: Call to undefined function get_option() After running the automated upgrade to 3.4, I receive the message > Fatal error: Call to undefined function get_option() in /.../wp-admin/admin.php on line 32 I have renamed plugins/ to plugins2/, renamed themes/ to themes2/, created themes/ and placed twentyten in there. Still fails with same error. I have downloaded a copy of 3.4, and uploaded /wp-admin and /wp-includes. Still fails with the same error. When I try to run wp-admin/upgrade.php I receive: "Fatal error: Call to undefined function timer_start() in /.../wp-admin/upgrade.php on line 20" Line 32 of /wp-admin/admin.php is: if ( get_option('db_upgraded') ) { I tried manually inserting this option set to true in the wp_options table in phpmyadmin, but the same error remains.
The problem was caused by about 8 wordpress files in the root directory with a filesize of 0 bytes. Uploading fresh copies of these files (from the latest version downloaded from wordpress.org) solved the initial problem. The subsequent problem has since cleared without any indication of what steps solved it.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "upgrade, fatal error" }
How to create custom LOGIN and REGISTRATION forms? I have developed a theme for Wordpress and I need to customize login and registrations form. At the moment, as usual, the login and the registration URL are: I would like to create INLINE form, with INLINE I mean that this form must to be inside my pages and not in a single(dedicated) web page. For login I need: - Email - Password For Registration: - Name - Email - Password (and a pseudo check for "spammers" like captcha or arithmetical operations) as I told I need these forms in my pages, not in a dedicated page. Two questions: 1- Can I do it **WITHOUT** using a plugin? 2- If I can, how can I show any errors (example: wrong email, wrong password) inline with the form? (without redirect to wp-login.php) Thank you!
## 1\. _Can_ you do it without a plugin? Certainly. Anything a plugin can do, you can obviously also implement yourself. ## 1.1 _Should_ you do it without a plugin? No. This is clearly plugin-territory. Even if you want to write the plugin yourself, this would be a better fit for a custom plugin than to incorporate it in your theme. That's a matter of preference and opinion though - of course it _can_ be done within your theme also. For the sake of completeness, let me mention Jeff Farthing's theme-my-login. It's a well written, powerful plugin that has been developed for years. It is for sure the (much) less work-intensive solution and you should at least consider using it before you hack away on writing something similar (and most likely less powerful). ## 2\. How can it be done? Have a look at the Administrative Actions and hook into those. Again consider downloading the above mentioned plugin and dissect how it works.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, users, login, user registration" }
Front-end editing with custom fields? I use the custom field plugin < Is it possible to create and edit custom posts via the front end? I'd need to be able to see all the custom fields and allow those to be edited as well. Users should only be allowed to edit their own posts if they are logged in.
you can do with **wp insert post** and **wp update post**
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom field, users, front end" }
Is it possible to order posts by two meta values? Hopefully this is a reasonably straightforward question! Is it possible to order posts, on the front-end of my WP install, by **two** meta values? I have a meta key called `genus` and another called `species`. I'd like to sort firstly by `genus` (ASC), then `species` (ASC). Thanks in advance,
AFAIK, you can't do it using a meta query. Check this example, does what you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "custom field, sort" }
wordpress localization extending I am using a .mo file in my language directory of wp-content. But It doesn't trnslate some words and all the numerical contents of the site. How can I add these to the .mo file? Or is there any other way to translate those contents?
If dont use the strings inside the theme or plugin the function for localisation, then it is not possible to add this to the mo/po file. You must change the source of the theme or plugin. But used the theme or plugin the functions, than parse the source via plugin or desktop tools to add the strings to the mo/po files. use: * plugin Localization * Desktop poedit
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "localization" }
How to initialize $wpdb? I have a .php page in the theme root to check the data of one CUSTOM form. After receiving this data I need to do a query in a custom mysql table, so I need $wpdb, but I can't use it directly (or doing `global $wpdb`) because it is a phisical .php file, so the rewrite rule will not affect the request (the request is not passed to index.php because the file exists). So In this case how can I create an object $wpdb? Thanks
First of all you probably created an isolated file that is not under the umbrella of WP files. That's why you are not getting $wpdb. I guess you may not following the general rules/conventions of theme development. my question is now how are you accessing the file? whatever, if you include the wp_config.php in your file, you will get the $wpdb in your file. considering in a directory under themes directory, here is how you include/require the file require_once ('../../../wp-config.php'); you may need to alter the path based on your system.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "database, oop" }
Should I use add_filter for functions in function.php of the theme? I have written few functions in the function.php file of the theme. Should I use `add_filter` function for those functions?
It depends on the things you want to do. you can use add_filter and add_action based on what you want to do. > **Actions** : Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API. > > **Filters** : Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API. so if you want to modify the content, you should hook using filter functions. For doing your own stuffs, you need to hook using action functions. if you have explained your purpose, we could probably tell you what you need to use. More details here: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, functions, filters" }
How to insert meta keyword to search result page I have search a lot but cannot find any solution for my problem. I when i entered the search term to the search box of my website, it goes to `mysite.com/search/search+term`. However, the result page does not have meta keywords and meta description. I trying to find way to add these values into the header of the result page with `meta keywords = search term` and `meta description = information about the search term`. I think i will need to modify the search.php or query.php files, but not sure how to do. I don't want to change the header.php because it will conflict with other normal posts. Anyone has any suggestion how to do this? Thank you in advance!
that is relatively easy. you can add this to your theme's functions.php file add_action('wp_head', 'add_meta_tags'); function add_meta_tags(){ if(is_search()){ $search_keyword = get_search_query(); echo '<meta name="META_NAME" content="META TESTING" />'; } } you may change `echo '<meta name="META_NAME" content="META TESTING" />';` as you want to output the meta tags. however, your theme needs to call `wp_head();` for this to work. check your theme's `header.php` file.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "search" }
Calling custom fields for pages (not posts) I'm trying to place a small code in my template `header.php` file. I want to get a custom field value. I'm trying to call custom fields from current page **outside** of loop, btw. I have no problem doing this when I need to get custom field values from posts, but I can't seem to do this for pages. Here is my code: global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'teaser-text', true); I'm not sure what I'm doing wrong. I tried changing `$wp_query->post->ID;` to this `$wp_query->page->ID;` to no success. Any help is appreciated, thank you!
try using get_metadata('post', $postid, 'teaser-text, true); these two actually same. should not make any difference. earlier i gave wrong arguments. var_dump() will show you what it is actually getting. please make sure, the ID is correct, 'teaser-text' exists. You can also try using some other meta name (for testing purpose only).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom field, pages, loop" }
retain querystring values when savincustom options in admin Quick question, I have a custom options page which posts to options.php, however I have a few sections to my options page where i change the post url like so: `<form action='options.php?section=sectionname' ..>` when the options page reloads I need to check which section was just saved i.e. get the sectionname from the querystring, however the options.php page redirects to the options-general.php page and does not retain my query string. can anyone think of either a way to retain the QS or tell me a better way to do this? Thanks
How about putting the current section in a hidden form field inside each section, and then when you reload the page, check `$_POST['section']`?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, admin, wp admin, options" }
Is there some way to provide the user a list of existing content in a CPT I was looking at the way WordPress uses "Or Link to Existing Content" under the link button in the editor and I am wondering if there is any way I can use that code to allow users to select a page to link to when they create a new custom post. The context I am talking about is that of slides for a slider linking to content within the site.
I've run across this before. What I did was use `get_posts()` to return a list of the pages in the site and making the pages options in a drop down menu in a meta box. // $your_args is an array that you've previously declared to get all the pages. $pages = get_posts($your_args); foreach( $pages as $page ) : ?> <option value="<?php echo $page->ID; ?>"><?php echo $page->post_name; ?></option> <?php endforeach; When you save the post, it will save the page's ID in the custom post's post meta.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development, theme development" }
Compare post-IDs within WP_Query? (Less than / Greater than) Can I use `WP_Query` to only query posts less than (or greater than) a given post ID? $filtered_query_args = array( 'post_type' => 'projects', 'order' => $prev_next=='next' ? 'DESC' : 'ASC', 'orderby' => 'ID', // ID <= $post->ID ); I've been digging around in the codex with no luck. I can of course do this conditionally within the loop, but it would be much cleaner if I could use `WP_Query` directly.
I ended up using something like this: function filter_where( $where = '' ) { global $post, $prev_next; $the_ID = $post->ID; $where .= " AND wp_posts.ID "; $where .= $prev_next=='next' ? "< $the_ID" : "> $the_ID"; return $where; } add_filter( 'posts_where', 'filter_where' ); $nextProjQuery = new WP_Query( $filtered_query_args ); remove_filter( 'posts_where', 'filter_where' );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, wp query, posts where" }
Displaying a list of tags in my archives page I'm looking to display a list of tags on my archives.php page. Here is the search archives page. I have archives by month <ul> <?php wp_get_archives(); ?> </ul> Archives by category <ul> <?php wp_list_categories(); ?> </ul> and now I'm trying to look through the codex for a way to display a list of tag links but none of them do that. I just want them to do exactly what my list of categories is doing. Why can't I find the right template tag for that? Any help is appreciated.
You can try using the tag cloud.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "search, tags, archives" }
Organize WordPress site, so it can maintain with huge database ## Intro: Hello, I am making coupon website and I need an advise. So, the structure at the moment is like this: 1. Coupons ( posts ) 2. Categories of coupons ( categories ) 3. Shops ( tags ) In the near future my database will consist of approximately ~5000 shops ( tags ) and ~20000 coupons ( posts ) and also ~10000 of categories of coupons ( cats ). I will also add deals to website soon, so this might be also taken into consideration. ## The question: What is the best way to organize such website, so it will work flawlessly after such huge amount of entries in database? Should I use **Custom Post Types** for any of my taxonomies? Thank you
Custom Post Types are more convinient and easy to implement, so I suggest you use them. Also the Posts will be ready to make a blog section in the future. About optimizing. 1. Use some caching plugin, there are lots of them in Wordpress Plugin Directory. 2. Turn off the revisions to save database size: add `define ('WP_POST_REVISIONS', 0);` into wp-config.php 3. And try to use as less plugins as possible. Only what you really need.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, database, capabilities, server load, taxonomy" }
How to remove and disable access to General Settings Page including its link How to remove and disable access to General Settings Page including its link on the Settings Tab and add a new link as General Settings?
There is a plugin called "Admin Menu Editor" that can do just this. I have used it numerous times without issues.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "multisite, admin menu, sub menu" }
How to enable automatic search results in WordPress I'm trying to find way to enable automatic search in WP. For example, I have a page `mysite.com/some-thing`. Within that webpage, I also want to display the content of the page `mysite.com/?=some+thing`. I don't want to use an `iframe` because I want the content of the second page (the search page) to be in the HTML source code of the first page. Is this possible to achieve? I'm thinking about using WP web scraper plugin, but it is difficult to implement the selector :-( Does anyone have any advice?
something like this in your page template, ideally after endwhile (if any) <?php $theQuery = strtolower(trim(get_the_title())); $args = ('s='.$theQuery .'&showposts=5'); $search_query = new WP_Query($args); if ($search_query->have_posts()) : while ($search_query->have_posts()) : $search_query->the_post(); //do your stuff endwhile; endif; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "pages, search" }
How to get the post publish date outside the loop? I need to pull out the post publish date in order to make the post post auto expire. The thing is I can't get the right publish date. Here is my code: global $wpdb; $post_ids = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_status ='publish'" ); foreach($post_ids as $id){ $postdate = get_the_date("Y-m-d",$id ); //here is what I can figure out ....... ......etc } When I echo the $postdate, it come out with a wrong date. Not the date that exist in the wp_posts table. How can I get the date properly?
`get_the_date` must be used inside the Loop. For outside the loop use `get_the_time`. $posts = get_posts(array('numberposts'=>-1)); //Get all published posts foreach ($posts as $post){ echo get_the_time('Y-m-d', $post->ID); //Echos date in Y-m-d format. } Consider replacing `'Y-m-d'` in this example with `get_option('date_format')` as this will display the date as per your date format setting in wp-admin.
stackexchange-wordpress
{ "answer_score": 20, "question_score": 10, "tags": "database, date" }
Shipping charge by country & product weight? I am using WP E-Commerce plugin. In my e-commerce platform, there is two variable for product price. Its based on location (ie. india, usa, canada (not by continent)), and weight also. How can I achieve this, is there any plugin ?
This looks like it might be perfect for you: Region Weight Shipping
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "e commerce, plugin wp e commerce" }
Form data to wordpress DB I am looking for ANY plugin which can save custom form(newsletter form, contact form) data to WP database (front-end) and then allow to browse the submitted data in the back-end (WP admin). Any tips much appreciated!
Best solutions would be: **Contact Form 7:** < **Contact Form to DB:** < Contact Form 7 to Database Extension: * export all of the data to DB * allows browsing and exporting * keeps every form data separate to browse/export Perfect solution!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, plugin development" }
Load different template file when condition met? If I visit a page on my WordPress site, WP goes and determines what template file it should use based on the template hierarchy. If I'm doing some logic checking in the hook `init` and say my conditions are met, how do I tell WordPress to load a template file of my choosing, not the one WordPress would normally dish up?
Can you perform the logic on the `template_include` filter? Else, you could set a global/constant and use that in `template_include` to serve up the appropriate template. The template_include filter filers the path to the template file to be included. To avoid errors you should check if the template exists - locate_template does this for theme/child-theme files. add_filter("template_include", "sc_redirect_properties_to_registration"); function sc_redirect_properties_to_registration( $template ) { if( is_user_logged_in() && ! is_page("the-properties") ) return $template; //You could include templates from plugins //$template = plugin_dir_path(__FILE__).'templates/plugin-template.php'; //Best to check the template exists. With **theme/child-theme** templates // you can do this with locate_template. return locate_template('template-registration.php'); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "filters, templates, hooks" }
Accessing Media/Files outside the_content I'm building a site and each post has a PDF file attachment. Is there a way I can access that file outside `the_content()` on a single post page? I'd like to put the file attachment in a sidebar and not in the body of the post.
I ended up using the WP-Filebase Download plugin. This allowed me to pull the attachments into a shortcode list that I could put in my template file outside `
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "uploads, sidebar, the content" }
How to get the role id from the role name? I need to retrieve the id of a role by giving it roles name. For example: if( current_user_can('editor') ) { //here I want to retrieve the id of editor. } How can I do that?
Try buildin function get_users. The code should be like that: $args = array( 'role' => 'editor' ); $editors = get_users($args); foreach ($editors as $user) { echo '<li>' . $user->ID . '</li>'; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "loop, user roles" }
Remove wpautop from shortcode content / remove whitespace in buffering I am using the Mailchimp plugin, and it has a shortcode that uses output buffering to grab its widget's code and spit it out in the content. However, the widget code has plenty of white space, so the_content filters are throwing useless linebreaks (like after hidden inputs) and empty `p` tags everywhere... rendering it unusable. I am removing the shortcode to add my own, but I'm not sure what to do to prevent the WordPress wpautop filter from going crazy. My initial thought was to strip out the whitespaces between HTML tags, but I don't know how to go about doing that. Ideally, the plugin would concatenate a string to return instead of using output buffering, but I don't know if they'll ever bother.
You do not need a plugin to do this. Just add 3 lines of code to the end of the `functions.php` file in your active theme: remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 99 ); add_filter( 'the_content', 'shortcode_unautop', 100 );
stackexchange-wordpress
{ "answer_score": 10, "question_score": 7, "tags": "shortcode, wp autop, plugin mailchimp" }
How to enqueue scripts depending on post formats? So I'm trying to enqueue scripts used for some post formats like video and audio and I could find a way to check what post formats are going to be shown on the page. I tried print_r on some global variables but they doesn't seems to have post_format in the post details, I tried $posts and $wp_query and also tried print_r on $GLOBALS. I also tried adding an action for video and audio post formats but the action runs too late for queuing scripts. have anyone done something like this before ? and thanks in advance.
Inside the Loop, try something like the following: <?php if ( get_post_format() && in_array( get_post_format(), array( 'audio', 'video' ) ) ) { // The current post has either the // audio or video post format; // enqueue a script wp_enqueue_script( $handle, $src ); } ?> Now that WordPress can handle inline script-enqueueing, this should work fine.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "posts, theme development, post formats" }
Need to download uploaded binary file I have uploaded a binary .war file which is nothing but a .zip file with Java web application extension. When I hit the URL for this file, I see junk characters in browsers. URL: < Need a way by which I can make the users download this file. By the way, I uploaded using FTP and the Add new media feature of WordPress gave me an error about File upload not supported due to security reasons. Pls. advise.
If your webserver is Apache, you'll need to tell apache what kind of mime type your file is, so Apache knows how to handle it. You should be able to use the "application/octet-stream" mime type in your .htaccess, in order for Apache to force a download. Learn more here: < (see the 3rd paragraph, starting with "A Handy Trick"). Regarding the media library -- by default, wordpress blocks most types of files from being uploaded. To allow more file types, you'll need to filter the allowed types. Add this to your theme's functions.php: <?php function custom_upload_mimes($mime_types) { $mime_types['war'] = 'application/octet-stream'; return $mime_types; } add_filter('upload_mimes', 'custom_upload_mimes'); ?>
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "uploads" }
How to set author for post AND post attachments I have multiple author accounts on one of my WordPress installs. Often I will create a post, and set the author to be a different account. However, when I upload images into that post, their attachment page lists the author as my account. How can I set the author for posts, and have it carry over to the media associated with that post?
Use this in your theme's `functions.php`: add_filter( 'add_attachment', 'wpse_55801_attachment_author' ); function wpse_55801_attachment_author( $attachment_ID ) { $attach = get_post( $attachment_ID ); $parent = get_post( $attach->post_parent ); $the_post = array(); $the_post['ID'] = $attachment_ID; $the_post['post_author'] = $parent->post_author; wp_update_post( $the_post ); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "attachments, post meta, author" }
Free WordPress plugins for membership? I'm looking to create a membership-based website and I'm new to WordPress so its been a headache trying to look for free plugins that can creates 3 levels of membership (non-members, members, and premium members) limit access to certain pages/functionality of the site to members/premium members Also can't find a good plugin for customizable registration form
Did you, by any chance, look up "wordpress membership plugin" on Google? The first link is for the Membership plugin on WordPress.org. You only need 2 levels of membership (members and premium), as regular users will be non-members by default. I suggest you do a Google search for "wordpress custom user registration" as well, because you'll find a free plugin for your second issue there. tl;dr - LMGTFY
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin recommendation" }
Is there a way to add a link with add_post_meta? I am trying to put a link in the post meta with this code $authorEmail = get_the_author_meta('user_email'); $authorEmailLink = '<a href ="mailto:'.$authorEmail.'">'.$authorEmail.'</a>'; add_post_meta($post->ID,'Author Email',$authorEmailLink,true); The `$authorEmailLink` is a valid link because I can echo it to the page. However, when I put it on the page, it just displays the plain text email. Is there something I am not doing or a way to get around this?
I don't think spaces are allowed in `$meta_key`. Try to change 'Author Email' to 'author_email'. Also, if you don't want 'author_email' to be visible in Custom Fields metabox, prepend it with underscore: '_author_email'. Unfiltered link as custom field value can also mess this metabox.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, post meta" }
I am trying to make a page in the admin section similar to the appearance of the Profile page for users I am working on a plugin and would like to know the correct way I go about creating a page that will look like the users page (image attached at the buttom) The fields will be different and will add data(the data is unrelated to user information) to a new table created by the plugin . So it does not seem like the Settings API will help me. I am strictly talking about appearance. Should I just use the css built in wordpress or is there some sort of function that will help me create all the fields?!enter image description here
If I understand you correctly you want to create a page for your plugin which mimics the look and feel of the WordPress Dashboard and it's option pages? If so then you can use the CSS which is packed with WordPress. The CSS file is located at wp-admin/wp-admin.css If you open that file with your code editor you can inspect some of the styling. Using this in conjunction with a code inspector like Firebug or Google Inspector you can check items you want to mimic by "inspecting" them and simply name your elements with the same style or ID that you wish to mimic for your plugin Craig
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, admin menu, input" }
Post AND page parameter for WP function Is there no post AND page parameter for WordPress functions? So would I have to create a custom post type to define post AND page? For example, `add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );` you need to define what type of `$post_type`. The options are 'post', 'page', 'link' or a custom post type. I'd like to define a meta box that applies to both the post and page. Surely copying and pasting the function and then replacing the $post_type with post and page would work but it wouldn't be very efficient. I know that `is_singular()` defines both a post and page, but that is for a query. Any ideas? I'd prefer not to install another plugin. One reason I am creating a meta box is so that I _don't_ have to install a plugin.
There's no reason you can't call add_meta_box() twice in a row and use the same function to display it both times; just change the `$post_type` parameter. **Example** foreach ( array ( 'post', 'page' ) as $post_type ) { add_meta_box( 'your_id', 'your title', 'your_callback', $post_type ); }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, functions, metabox, post meta, parameter" }
Select menu on browser resize I have seen on some wordpress themes that if the browser width is less, the normal menu becomes a select menu. Can someone tell me how it is done? I know there is a plugin for that, but I want to know how to implement it in the theme without plugin. Thanks
I think the plugin you mention is the one I wrote so if you're looking for answer on how to do it take a look at the code. < Essentially all I did was create a custom menu walker class so I could output the menus created in the backend as a dropdown. If it helps my plugin can actually be packaged within in a theme and included via the functions.php. Just wrap the include in a `!function_exists('dropdown_menu')` test and you're good.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "theme development, menus, themes" }
Custom Page Template for "Older Posts" Pages My home page feed has a variety of items including a featured post and other features that I'd only like present on the home feed. When a user clicks on pagination to load older posts, I'd like to load up a new page template without all the home page bells and whistles. Is there a WP template file I'm overlooking or is this not supported?
Consider using the `is_home()` conditional tag to check whether or not the home page is being displayed or not. <?php if ( is_home() ) { // This is a homepage // Do your fancy loop here with extra bells and whistles } else { // This is not a homepage (i.e. paginated page) // Do a stripped down version of your loop above with no bells and whistles } ?> Reference to is_home on the WordPress Codex
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pagination, templates, page template" }
Why to check if function doesn't exists in functions.php? I see in the twentyeleven theme, before most custom functions they check if it exists <?php if ( ! function_exists( 'twentyeleven_comment' ) ) : function twentyeleven_comment( $comment, $args, $depth ) { Why is that?
A child theme may have declared these functions already with a slightly different inner logic. The `functions.php` from the child theme is loaded before the file from the parent theme. Without this check you would get the _Cannot redeclare …_ error. Plugins can create functions too, so this problem is not restricted to the themes that are written with child themes in mind.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "theme development, theme twenty eleven" }
Override orderby to create list of users by custom meta_value I'm having issues ordering a loop of users by a custom meta_value. Reading the Codex for `get_users()`, it doesn't actually say that you can use the `meta_value` for orderby. When I try to do it I get a list of users not ordered by the meta_value. <ul> <?php $args = array( 'role' => 'author' , 'meta_key' => 'score', 'orderby' => 'meta_value_num',//Tried meta_value also 'order' => 'DESC', 'number' => 5, ); $blogusers = get_users($args); foreach ($blogusers as $user) { echo '<li>' . $user->display_name . '</li>'; echo get_user_meta($user->ID, 'score',true); } ?> </ul> So what I need to do is override the orderby function by hooking into the pre_user_query. I found this snippet but was told not to use create_function. So what is the right way to do this to order a list of users by user meta_value?
Try this code, but replace `METAKEY` to the key-name of your metadata. <?php function cmp( $a, $b ) { if( $a->METAKEY == $b->METAKEY ){ return 0 ; } return ($a->METAKEY < $b->METAKEY ) ? -1 : 1; } ?> <ul> <?php $args = array( 'role' => 'author' , 'meta_key' => 'METAKEY', 'number' => 5, ); $blogusers = get_users($args); usort($blogusers ,'cmp'); foreach ($blogusers as $user) { echo '<li>' . $user->display_name . '</li>'; echo get_user_meta($user->ID, 'METAKEY', true); } ?> </ul>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, users, meta value" }
cat_is_ancestor_of() for custom taxonomies I'm trying to use cat_is_ancestor_of() for custom taxonomy categories but it's not working. Is there any other way to check if a category is child of another?
Use `term_is_ancestor_of()`. That is the function `cat_is_ancestor_of()` is calling: term_is_ancestor_of( $parent, $child, 'taxonomy_name' );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "categories, custom taxonomy" }
Add filter on certain thumbnail sizes only How to run this filter only on some specific registered thumbnail sizes '$size' ? like 'large' , 'medium' .... add_filter( 'wp_get_attachment_image_attributes', 'wpse8170_add_lazyload_to_attachment_image', 10, 2 ); function wpse8170_add_lazyload_to_attachment_image( $attr, $attachment ) { $attr['data-original'] = $attr['src']; $attr['src'] = 'grey.gif'; return $attr; } Thanks
This is a hack, but I guess it should work... add_filter( 'wp_get_attachment_image_attributes', 'wpse8170_add_lazyload_to_attachment_image', 10, 2 ); function wpse8170_add_lazyload_to_attachment_image( $attr, $attachment ) { //use your image size here with attachment if($attr['class'] == 'attachment-large'){ //do your stuff } return $attr; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails, filters" }
Showing posts from different categories and from custom post type On my main page, I want to show posts from 3 categories, and 1 custom post type. Is there a way to get them together in one `pre_get_posts` function? Or do I need to query separately - once for the CPT and once for the posts from specific categories?
If you are after on post from category a, one from category b, another form category c and then finally a custom post type - each of these would have to be a separate query. Think of these as 'secondary queries' - (the primary query being what lands you on the home page). So you'll want use seperate instances of `WP_Query` (see this related post). E.g. $post_from_cat_a = new WP_Query(array( 'category__name' => array('a'), 'posts_per_page'=> 1 )); if( $post_from_cat_a->have_posts() ){ while( $post_from_cat_a->have_posts() ): $post_from_cat_a->the_post(); //Display output here endwhile; } $post_from_cat_b = new WP_Query(array( 'category__name' => array('b'), 'posts_per_page'=> 1 )); if( $post_from_cat_b->have_posts() ){ ... ... etc. Don't forget to call `wp_reset_postdata();` at the end.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, posts, categories, pre get posts" }
can't access backend while frontend works perfect Before 2 days there was a automatic update for wordpress, which I for my website. When the update was over, I tried to access backend but I always get this message: Fatal error: Call to undefined function wp_is_mobile() in /home/*******/public_html/wp-login.php on line 67 Can you give me any idea what to do, how to fix this. Thanks
/!\ **Before change I suggest, please make a full backup (code + database) of your Wordpress.** * Deactivate all plugins. If it does not help try next * Re-upload all files and folders ( **except the wp-content folder** ) from a fresh download of WordPress.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp admin, automatic updates" }
insert a warning message into post-new.php wondered if anyone knew the most elegant way to insert some sort of warning message each time someone tries to create a new post, i.e. 'please remember what you publish is your own responsibility', that sort of thing. I'm thinking I'd like to use the error or warning css wordpress uses if it can't find something or there's an error some place. I'd have thought calling it from the functions file would be best so it doesn't get overwritten each time I update but not really sure what to search to find the reference for it, any ideas?
function my_admin_notice(){ global $pagenow; if ( $pagenow == 'post-new.php' || $pagenow == 'post.php') { echo '<div class="error"> <p>This notice only appears on the add and edit post & page.</p> </div>'; } } add_action('admin_notices', 'my_admin_notice'); <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "posts, warnings" }
How to cause the Wordpress web interface to update via FTP On some installations of Wordpress, all updates performed through the administrative web interface require the FTP username and password to be entered before they take place. Others update and install themes/plugins just fine without needing FTP information. I'd like to test some permissions hunches by forcing the web administrative interface to update via FTP. Is this possible? ( **Note:** Certainly using a regular FTP client would work, but I'd like to keep the client away from as many additional steps and applications as possible. Keeping them to the web interface would make life... simpler.)
The problem with WordPress not being able to install plugins or update itself is because WordPress uses the Apache 'user' for all its processes. In the case of Ubuntu / Linux the Apache user and group is www-data:www-data. By doing `sudo chown www-data:www-data /wordpress` your changing the ownership of all files. A problem can occur if _your_ user account is not in the same group as `www-data` for example you FTP'd a new image to your wordpress folder and it's permissions were wrong, then it may not show up on your website. So you should also change your users Primary Group to `www-data`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "ftp" }
Extra Text in URL I'm redesigning my website. The blog posts and everything were fairly easy to move to the new wordpress install. The URL of the test site is this: < When I go to that URL I have this URL show up in the address bar: < but when I hit the home button at any time the site goes to NathanTornquist.com/wordpress as it should. What do I need to do to correct this behavior?
The extra "nathantornquist" in the URL happens when you don't have the trailing slash on ` What are the contents of your .htaccess file?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "redirect, homepage, home url" }
How can I scale down the width of images in bulk that are embedded in posts throughout the site? I am building a new WordPress theme and it is quite different from my current theme. Currently the dimensions of my images are much wider than how I would like them to be for my new theme I am developing. Is there way to scale down the widths programmatically and in mass? Is there a plugin that accomplishes this task?
if what you need is to apply this to big images (no thumbnails like in Gembel's solution) you can use CSS, including a max-width statement. For example: .content img{width:98%; max-width:200px;} of course you should adapt the numbers to what you need, but you'll get the idea
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, post thumbnails, images" }
How to display date such "x ago" I want display date based on how much time has passed since, i. e. _Posted 12 minutes ago_
This is quite simple: just replace the `get_the_date()` or `the_date()` with echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "themes, date time, date" }
Filter link to existing content suggestion How can i filter the link given in "link to existing content". Eg:!enter image description here As in the above image. I just want WSP BANNER TO BE SHOWN. where WSP BANNER & CALENDAR are custom POST types Any help will be appreciable.
Currently there are no ready filters available for this purpose. A ticket has been posted for the request.Lets hope we get one soon. Instead of hardcoding your custom post types its better to create a filter hook and use it Till then you can create your own filter. Open includes/class-wp-editor.php and make folowing changes at line no 712 $pt_names = apply_filters('custom_insert_link_suggestion_filter',array_keys( $pts )); we just added a new filter instead of getting all the public post types Then in your theme add following code to filter the internal link custom post type function my_filter_function($allowed_post_types) { if( condition chek) { return array('page','your custom post types'); } } add_filter('custom_insert_link_suggestion_filter','my_filter_function',10,1);
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "php, filters, links" }
WordPress Widgets no drop down i gave my editor role an access to my Widget settings. But i wonder why it is different when an admin access it. It has no drop down. see the attachment: Thanks Ivan
You have accessibility mode enabled. To get the regular arrow drop down disable accessibility mode through the screen options menu. !enter image description here
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "widgets" }
WPML - how to translate user profile fields with icl_t()? Existing code somewhere in a template or shortcode handler, display user profile biography: <?php if ( $user ) : $bio = get_the_author_meta( 'description', $user->ID ); ?> <div class="esineja_info"> <span class="bio"><?php echo $bio; ?></span> </div> How do I get these biographies to show up in WPML String Translation. This is not making it happen: $bio = icl_t( 'theme', 'bio-' . $nimi, get_the_author_meta( 'description', $user->ID ) ); This help page isn't particularly helpful to me, at least I cannot figure out how to apply it to this situation. This problem-specific thread is also quite vague on how exactly icl_t() is supposed to be used.
It turns out, my code above is indeed all that is needed. Apparently the mistake I made was that I didn't load the translated version of the page in the frontend at least once, so icl_t() didn't auto-register the strings. Also keep in mind, if you're looking at correct string count in String Translation context names, you need to put "theme blah" as your context if you want icl_t() strings to get unified with the rest of the theme strings. Just icl_t( "blah", ... ) will create a new context named exactly "blah".
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "user meta, translation, plugin wpml" }
add span to wp_nav_menu widget Am using the custom menu widget to add a menu in the footer and i want to add a in the menu how can i do this ? like so... <li><a href=""><span>menu1</span></a></li> if done it for the main nav using the link before below but as this is a widget am not sure where to add this 'link_before' => '<span>', 'link_after' => '</span>' any one know ?
Filter `'walker_nav_menu_start_el'` and replace the link text. Prototype, not tested: add_filter( 'walker_nav_menu_start_el', 'wpse_56028_title' ); function wpse_56028_title( $item ) { return preg_replace( '~(<a[^>]*>)([^<]*)</a>~', '$1<span>$2</span></a>', $item); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "menus" }
Debugging WordPress themes with Xdebug, real time html output Hi I'm using XDEBUG to debug my WordPress code, is it possible to view the page building up in the browser while debugging? At the moment the page just hangs until the debugging process is finished then displays the fully rendered page. Ideally I'd like to see the page building up bit by bit as I debug through the theme's code.
Just an Idea - I did not test this. Worth a try would be to play around with your PHP settings: ; Implicit flush tells PHP to tell the output layer to flush itself ; automatically after every output block. This is equivalent to calling the PHP ; function flush() after each and every call to print() or echo() and each and ; every HTML block. Turning this option on has serious performance implications ; and is generally recommended for debugging purposes only. implicit_flush = On I would also recommend to disable gzip and look for other output_buffering related options in php.ini. Then you should be able to set break-points in the different rendering stages of your theme.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 6, "tags": "debug" }
Contact form 7 select box different value-text than content-text in option Does anyone know how I can set a different value in the select options in the Contact Form 7 plugin? Here is an example of the HTML I'd like it to generate: <select> <option value="1">My car</option> <option value="2">Your car</option> </select>
It looks like this is supported by Contact Form 7 natively, it's just not very obvious on how to make it happen. Here's a documentation page explaining the functionality: < Basically, all you have to do is put the values like so: "Visible Value|actual-form-value" What comes before the pipe `|` character will be shown in the form, and what comes after will be the actual value filled in for the form. Hope that helps!
stackexchange-wordpress
{ "answer_score": 25, "question_score": 16, "tags": "plugins, forms, options, plugin contact form 7, select" }
Hide content after going to page 2 of archive, show content when back at first page I want to hide the content below when the user uses pagination to move from the initial page of the archive (page 1). Is there some way of detecting whether or not the current page is page 1? Content below needs to reappear if the user returns to page 1. <!--Hide Me if not on page one--> <div class="oneThirdColumn alignLeft"> <!-- Rigth Column --> <div class="colTopHeader"> <h2>Filter Products</h2> <div class="clear"></div> </div> <!-- Faceted Search --> <?php dynamic_sidebar( 'secondary-widget-area' ); ?> </div> <!-- end Rigth Column --> <!--Hide Me if not on page one-->
There is an example on the wordpress codex. (link). Basically you use an if statement on the variable `$paged` which stands keeps track of the current archive page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "pagination" }
Altering term_id and name via $wpdb class $s = $_POST['submitterms']; $querystr = " SELECT $wpdb->terms.* FROM $wpdb->terms WHERE lower($wpdb->terms.name) like '%$s%' "; $pageposts = $wpdb->get_results($querystr, OBJECT); echo '<ul>'; $x = 0; while ($pageposts[$x]) { $post = $pageposts[$x]; echo '<li>'; echo '<a href="' . $post->term_id . '">' . $post->name . '</a>'; echo '</li>'; $x++; } echo '</ul>'; I'm able to get term names that contains the characters i typed into the text box. But what i want to do is changing `term_id AS id AND name AS value` so that i can pass the variables like: $post->id $post->value //i.e echo '<a href="'.$post->id.'">'.$post->value.'</a>'; I guess i need to change the MySQL code. What should I do?
You can do it easily. Your query should be: $querystr = "SELECT `term_id` AS `id`, `name` AS `value`, `slug`, `term_group` FROM {$wpdb->terms} WHERE lower($wpdb->terms.name) like '%$s%'"; See, here i've mentioned the name of the fields needed. For any other fields, you need to explicitly mention the field names.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, terms, wpdb" }
If I use Apache & ngnix together will I have fewer problems? I have a VPS set-up and because it had limited RAM I set it up to run nginx instead of apache. But although performance has been reasonable, I've had problems with things like multi-site rules and plugins complaining. I was wondering if I used Apache and Nginx together, with nginx serving static files, apache php would I get both performance and compatibility? I am thinking of setting up my VPS in a similiar manner to the 2nd answer to this question: What is the best caching option for WordPress multi-site on non-shared hosting?
> If I use Apache & ngnix together will I have fewer problems? Yes, of course. Please be sure to install and setup mod_rpaf in Apache, if you are going to setup Nginx as reverse proxy to Apache. > I was wondering if I used Apache and Nginx together, with nginx serving static files, apache php would I get both performance and compatibility? Performance is purely based how you configure these. Your site will, of course, be more compatible (for plugins).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "apache, nginx, vps" }
Multiple users editting widgets I have just completed a website using WordPress as a CMS, the site has 6 people administering the content and in the couple of days before launch all 6 were updating the content. We found that if multiple people were editing/creating widgets at the same time this would save over and some of the widgets were deleted. I'm assuming this is because widgets are stored in a serialized array when the user is pressing save its adding an array which doesn't contain the widget the another user is editing. Obviously this can be a bit frustrating for the users so I was wondering if anyone else has had this problem and if there was a way to only allow one user to edit widgets at a time?
I have never personally had this problem, but to the best of my knowledge WordPress does not have the system to support multiple users managing widgets at the same time, at least not widgets in the same widget areas. Is it a problem to just have one user at a time manage the widgets? I can't really imagine that being a problem, as 99% of the time you set widgets once and don't change them for extended periods of time. If the site requires that widgets be frequently (more than once per day), then I would seriously consider improving the site infrastructure to NOT require this. Use posts, pages, or custom post types to hold the content and widgets to display the items.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "widgets, admin" }
Permalink: postname EXCEPT for blog In order to refrain from possible duplicate URLs or conflicting URLs, I really want to use "postname" for a clean URL structure, EXCEPT for the blog ... for the blog and it's posts, I always want /blog/ to be apart of the URL. This makes total sense, and I don't quite understand why it doesn't function like this when you specifically select a Page to represent the blog.
I've come to accept that this is just a limit of WordPress.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks, blog, blog page" }
How can I display widget in a Page or Post? I am trying to display some widgets (Quora & Goodreads) widgets inside Page or Post. How do I do that without displaying it inside Sidebar?
There's no easy way to do this. Many plugins that provide a widget _also_ provide a shortcode (text in brackets that you can put in your post like this: [quora]). I have no idea whether either of your widgets also come with shortcodes. Though I've never used them, there are some plugins that claim to help you do this. (Like this one.) If there isn't a shortcode and you can't find a plugin, your last option is to write your own shortcode that runs `the_widget()`. You'll need some low- to moderate-PHP ability to do this. I've never tried it, so I can't say whether there are any caveats to this solution. With a quick google search, I was able to find this tutorial for making a shortcode that runs `the_widget()`. Good luck!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "posts, pages, widgets" }
Sends out email to admin Are there any plugin or code that sends out a email to me (admin) when a author or writer publish a post?
No need for plugin here are a few lines of code you can modify and paste in your themes functions.php file and you will get a new email whenever a post is published: add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){ $to = '[email protected]'; $subject = 'mail subject here'; $message = "your message here ex: new post published at: ".get_permalink($post_id); wp_mail($to, $subject, $message ); }
stackexchange-wordpress
{ "answer_score": 10, "question_score": 6, "tags": "posts, admin, email" }
All permalinks go to products page with WP E-Commerce plugin? I realize that maybe this isn't the best place to ask this, but since getshopped.org (the makers of the plugin) don't seem to have any support form, AND since I am unable to access the forums I'm posting here... After installing WP E-Commerce to test how it works, I discovered that all links to blog posts and pages on my site go to the WP E-Commerce page. I've looked at the FAQ and nothing seems to fix this problem of all my links going to the wrong place now. Any help would be appreciated.
Permalinks in settings were set for default. Changing them to /%category%/%postname%/ fixed my problem and now all posts and page permalinks go where they are suppose to.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "e commerce, plugin wp e commerce" }
Display posts with tag that matches current post title How would I show posts that have a tag who's name matches the title of the current post? For example if you are on a post called "Hippo" at the bottom of the page I would like posts with the tag "Hippo" to be displayed.
The query would look something like this: $title_tagged_posts_query = new WP_Query( array( 'tag' => strtolower( get_the_title() ) ) ); while ( $title_tagged_posts_query->have_posts() ) : $title_tagged_posts_query->the_post(); //Output whatever you want here. endwhile; This assumes that the tag slug for "Hippo" is "hippo", which should normally be the case.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, query posts, tags" }
Too many actions/filters! New to wordpress here. The concept of actions/filters in and of itself is not too difficult to grasp. What I am overwhelmed by is the HUGE amount of actions and filters available. When I am looking at tutorials/guides, they say "simply add this function to the wp_head action or after_setup_theme". Without these tutorials, how on earth would i know to hook that function to that action? As a beginner, how the heck would i know what is the appropriate action to hook on to? Any advice on how to navigate this? Thanks
Take a look at Mike's answer to a similar question more specifically the plugin he posted there can be used to create a list of all action hooks and filters that were called to generate that page in order of execution.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "filters, hooks, actions" }
How to verify nonce from Bulk/Quick Edit in save_post? I need to do something specific in my `save_post` callback for bulk and/or quick edits, so how do I check the nonce for that? I can only find `_wpnonce` in the `edit.php` html source, but can't find an action to match it with. I also tried `check_admin_referrer()` (no arguments) but it fails. 1. What nonce whould I check for? OR 2. Should I check for something else in `save_post` to know it's being fired from a a. bulk edit or b. quick edit action? I read that `DOING_AJAX` is there for quick edit, but is that enough on its own? what about for bulk edit?
I found `check_admin_referer('bulk-posts')` in wp-admin/edit.php:49 for bulk edit. With @Rutwick Gangurde's help, I found `check_ajax_referer( 'inlineeditnonce', '_inline_edit' )` in wp-admin/includes/ajax-actions.php:1318. Thanks y'all.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "ajax, save post, bulk, nonce, quick edit" }
delay function on publish? I have this function where I call a custom function through the add_action hook: `add_action('publish_post', 'custom_function');` ... now it works perfectly, but the I want the custom_function to be delayed so it runs AFTER the post has been published. BUT, if I add `sleep(20)` inside the `custom_function` it delays the post itself. What I want is the post to be published, and THEN run this function after x seconds. Thanks!
`publish_post` is called after post is published! So, you already got covered. but if you want to run an action after a certain time of the post is published, it's better to write a cron job. For example, if you need to run the function after 5 minutes of the post is published, you need to register a single cron event that will be triggered after 5 minutes from now (post publish) add_action('publish_post', 'register_single_cron'); function register_single_cron($id){ wp_schedule_single_event(tim() + 300, 'custom_function'); } function custom_function(){ //your logic goes here } Please check the api details here. But this system has one problem, it will not be triggered until site is loaded/visited on or after the scheduled time.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, actions" }
Set minimum number of characters in the search I would like to establish a minimum number of characters in the search. On sites that have many entries, spammers tend to type very short terms as "a" or "of", and the server collapses while trying to return the results. Therefore, I would like to establish the minimum number of characters for the search to be made​​, for example, three characters. Relevanssi plugin seems to do this. But I would do without using any plugins. Thanks in advance.
Quick and dirty, put this before your get_header() in your search.php <?php // Get the query string $query = get_search_query(); // if the first & last char is space, rip them $query = trim($query); // if there are more than one space, rip to one space $query = preg_replace('/\s\s+/', ' ',$query); // if chars count is less than 3, redirect them to homepage if (strlen($query)<3){ wp_redirect( home_url() ); exit; } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "search, characters" }
Do not allow to search certain words I would like to delete (not allow) searches with certain keywords (eg "of", "a"). If the search is done using exactly these terms, do not return anything or redirect to 404 page ... Thanks guys.
Try this in your `functions.php`, and change `news` for whatever you want to be blocked in your site. add_action('wp', 'check_search'); function check_search() { global $wp_query; if (!$s = get_search_query()) return false; if (preg_match('/news/', $s)) { $wp_query->set_404(); status_header(404); get_template_part(404); exit(); } } Hope it helps.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "search, exclude" }
Limit the number of pages created by the paging Any way to limit the number of pages that are created automatically by paging? I would limit to five pages in all, authors, tags, categories ... Ex: "site.com/tag/news/page/5", "...author/admin/page/5." Thanks.
This seem to work. Put in your `functions.php`: add_filter('pre_get_posts', 'limit_pages'); function limit_pages($query) { $query->max_num_pages = 5; if ($query->query_vars['paged'] > 5) { $query->query_vars['paged'] = 5; $query->query['paged'] = 5; } return $query; } But I guess you would still need some workaround for posts pagination and authors. Hope it helps you a little.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "pages, pagination, limit" }
"Donate to this plugin" for WordPress.org Plugin Authors I recently saw a link titled **"Donate to this plugin >"** link on a WordPress theme (and then I did!). How is this added to a plugin's page on wordpress.org? Here's a screenshot: !Screenshot of "donate to this plugin" on WordPress.org
It is read from the infos on your plugins readme.txt. Example from my Default Values for Attachments > === Plugin Name === > > Contributors: moraleida.me > > Donate link: < > > Tags: attachments, default values, caption, title, description > > Requires at least: 2.5 Tested up to: 3.3.2 Stable > > tag: 0.1 License: GPLv2 or later License URI: > > <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "plugins, plugin development, wordpress.org" }
Make tag cloud links consistent I'm using this code: ` <?php wp_tag_cloud( array( 'taxonomy' => 'channels') );?>` To display custom taxonomy as a cloud tag. How can display with all links being the same size? I can't seem to override the inline styles.
How about passing the `smallest` and `largest` arguments to `wp_tag_cloud()` and making them both the same? <?php wp_tag_cloud( array( 'taxonomy' => 'channels', 'smallest' => '1', 'largest' => '1', 'unit' => 'em', ) );?> Update: use `get_terms()` to get multiple taxonomy terms: <?php $terms = get_terms(array('channels', 'stations')); if (is_array($terms)) : ?> <ol> <?php foreach ($terms as $term) : ?> <li><a href="<?php echo get_term_link($term) ?>"><?php echo $term->name ?></a></li> <?php endforeach; ?> </ol> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom taxonomy, tags" }
OOP Plugin: Where should I place the action hooks in the class? Where in my admin class should I place the action hooks for adding css, scripts and the add menu page? In the __construct? Or should they be placed in a method?
Since you are using OOP, you probably want to architecture your plugin more efficiently. This is fine, but you'll be the one to structure your classes and build them. So what if you put it in the __construct() function? That's fine, as long as you initiate a new instance of the class. Putting it in a method (private or public) will give the same thing as long as you call that method from inside or outside of your class. I do use OOP for almost all of the WordPress plugins I create. Usually, I use the construct() function to add hooks for enqueue(ing) CSS, Scripts or other actions and filters. However, this is completely up to you, and you are free to design your classes as you wish.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, hooks, actions, oop" }
Change menu item order My primary navigation menu consists of pages, categories, and custom taxonomy. It appears to be in a random order. How do I adjust the order of the links? (the drag/drop in wp menus panel doesn't seem to have any effect)
Turns out under my theme (Bones) bottom position is actually the first one to display on front end. I had it backwards.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "menus, links" }
What if I have a large file on the server that I want the wp library to have? I have one server that has wordpress in the root directory. However before I installed wordpress, I also have (root)/videos. I'm sure I can move this folder anywhere, however I want to move it to a place so wordpress can add it to its media library. This way, I can easily select it. I don't want (and I can't) re-upload these large video files through the wordpress upload. Thank you
I did flag this question as a duplicate of this one: Is there any way to add images to the Media Library through a path on the server?. Which points to the plugin Add to Server as the article linked by @RyanB in the comments... But, wondering on the issue, a creative solution is uploading a bunch of dummy files with the same names of the big ones and replace them with the real ones inside the `/uploads/` folder. This would only work with audio and video files as they don't generate thumbnails nor metadata.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "uploads, media, media library" }
[Multisite]How can I update custom blog option? I wanted to update custom blog option created thru Settings Api using the function `update_blog_option`. I created this code. $country_base = get_blog_option($blog_id, 'mytheme_options');//retrieve all options $country_base['country_base'] = $the_country; $currency_unit = get_blog_option($blog_id, 'mytheme_options');//retrieve all options $currency_unit['currency_unit'] = $d_currency; update_blog_option($blog_id, 'mytheme_options', $country_base); update_blog_option($blog_id, 'mytheme_options', $currency_unit); However, its not working.. Is there way to update custom blog option?
As per the Codex on update_blog_option: > Switches to the blog id specified, runs update_option() and then restores to the current blog. If $refresh is true then it will refresh the blog details. * * * Not tested, but I think your problem is trying to update elements of the array instead of the whole thing: $the_options = get_blog_option($blog_id, 'mytheme_options');//retrieve all options $the_options['country_base'] = $the_country; $the_options['currency_unit'] = $d_currency; update_blog_option($blog_id, 'mytheme_options', $the_options);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "admin, settings api, options" }
Brute force attack? I'm seeing this quite often: !enter image description here No OS, same Browser, weird hostname -- they're definitely not real users. Can I do anything to take precautions before they do something? Thanks!
There's an ~~app~~ plugin for that, Limit Login Attempts. Some more info available in this wp beginner post: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "login, security, hacks" }
Front page welcome message area How i can create a welcome message area for my frontpage with backend control {admin panel} ## Welcome message
Create a page theme, then call it in `index.php`: $recent = new WP_Query( 'page_id=**ID**' ); while ( $recent->have_posts() ) : $recent->the_post(); ?><h3><?php the_title(); ?></h3><?php the_content(); endwhile;
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "frontpage" }
How can i show Cubepoints ranks/points in bbpress replies i've been searching for a while now on how to show Cubepoints Points and Ranks in bbPress replies right below the user avatar and name... Found the template file where to show the info, tho not sure this would be the correct one to grab the reply-author info, the "loop-single-reply.php" and just bellow bbp_reply_author_link(); i'm placing the output (correct me if i'm wrong), and i discovered the functions to calculate and display Cubepoints and Ranks (cp_displayPoints($user->ID); & cp_module_ranks_getRank($user->ID)), correct me if i'm wrong again ^^ The question is, since working with bbpress is way more harder then wordpress due to the lack of easy to reach documentation (like wordpress codex), how can I get the reply-author ID and display the Cubepoints and Ranks, am I in the right way? what am I missing? thank you in advance!
I found the solution of the problem, it goes like this: <td class="bbp-reply-author"> <?php do_action( 'bbp_theme_before_reply_author_details' ); ?> <?php bbp_reply_author_link( array( 'sep' => '<br />' ) ); ?> <!--Ranking --> <div class="bbp-ranking"> <span class="bbp-rank"><?php echo cp_module_ranks_getRank(bbp_get_reply_author_id()); ?></span><br /> <span class="bbp-points"><?php echo 'Reputação: '.cp_getPoints(bbp_get_reply_author_id()); ?></span> </div> <!--Ranking --> <?php do_action( 'bbp_theme_after_reply_author_details' ); ?> </td> in loop-single-reply.php
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "bbpress, cubepoints" }
Random image from tag/custom type on sidebar How would I pull a single random image from custom post type "athletes" and the custom image field "athletethumbnail" to be displayed in my sidebar? (I have PHP enabled for my text widget on sidebar.)
If I get your question right, as you mention Tag in the title, but not in the Content - and also mention a _random image_ but then it's not a library image but a custom field value... So, the following code will grab 1 random custom post type that has a custom field value that's not empty. And it's a mix of `get_posts`, `get_post_meta` and `Custom_Field_Parameters`: $args = array( 'numberposts' => 1, 'orderby' => 'rand', 'post_type' => 'athletes', 'post_status' => 'publish', 'meta_query' => array( array( 'key' => 'athletethumbnail', 'value' => '', 'compare' => '!=' /* will not grab posts with empty Custom Field */ ) ) ); $show_albums = get_posts ( $args ); echo get_post_meta($show_albums[0]->ID,'athletethumbnail',true);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, custom field, widgets, sidebar" }
Insert attachments from custom uploader into post (regular uploader style) I recently started using this nifty meta box framework: < I really like the plupload meta box, however, I need to be able to add the uploaded image into the editor rather than just attaching it to the post. Any idea how I can create a button that inserts the correct attachment into the editor like it works with the regular "insert into post" button when uploading using the regular uploader?
You can add content to the editor via javascript: tinyMCE.activeEditor.selection.setContent('<img src="hello.jpg">');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "uploads, attachments, tinymce, media, editor" }
URL rewrite with add_rewrite_rule and attachment_id I'm trying to add a rewrite rule to make this: mysite/?attachment_id=106 look like this: mysite/series/106 I've looked everywhere in this site and others and it's very confusing because there are lots of different ways to do it. I've tried editing the `functions.php` file in my themes folder, adding this at the beginning of the file: add_rewrite_rule('series/([^/]+)/?$', 'index.php?attachment_id=$matches[1]', 'top'); And the latest one I've tried: add_filter( 'query_vars', 'wpa56345_query_vars' ); function wpa56345_query_vars( $query_vars ){ $query_vars[] = 'attachment_id'; return $query_vars; } add_action( 'init', 'wpa56345_rewrites' ); function wpa56345_rewrites(){ add_rewrite_rule( 'series/(\d+)/?$', 'index.php?attachment_id=$matches[1]', 'top' ); }
Place the code suggested below in _functions.php_ of your desired theme, it worked for me with WP 3.4:
stackexchange-wordpress
{ "answer_score": 2, "question_score": 4, "tags": "attachments, rewrite rules" }
Which filters or actions to use after a media upload and delete? When a media (image) is uploaded and the subsequent images are created (all the different sizes), I would like to perform a few actions. It is simple and I basically need only the new attachment ID, that would be enough. Same during deletion: before or after deletion, I need to know which attachment ID is concerned. Thanks for your help :)
i guess you are looking for this `add_attachment` and `delete_attachment` example: add_action('add_attachment', 'attachment_manipulation'); function attachment_manipulation($id) { if(wp_attachment_is_image($id)){ //do your own tasks } }
stackexchange-wordpress
{ "answer_score": 8, "question_score": 7, "tags": "uploads, media, media library, images, wp filesystem" }
Save post meta foreach loop My brain has fallen over. How do I save this post data? Building some key-value pairs in the form. for ($i = 1; $i <= 3; $i++) { $saved = $meta[$i]; //print_r($saved); //echo $saved['key']; echo '<p>'; echo '<label for="meta_k_'.$i.'">Key</label> ', '<input id="meta_k_'.$i.'" type="text" name="_meta['.$i.'][key]" value="'.$saved['key'].'" />&nbsp;&nbsp;'; echo '<label for="meta_v_'.$i.'">Value</label> ', '<input id="meta_v_'.$i.'" type="text" name="_meta['.$i.'][value]" value="'.$saved['value'].'" />'; echo '</p>'; } How do I save them??? foreach ($_POST['_meta'] as $key => $value) { update_post_meta($post_id, $key, $value); }
This should be work: foreach ($_POST['_meta'] as $value) { update_post_meta($post_id, $value['key'], $value['value']); }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "post meta, save post" }
Limit Media Library to Given Folder I have made a plugin that uses the Media Library to allow users to upload files to a specific directory - using the `upload_dir` filter. I would like to know if there is a way (i.e. a filter) I can use to limit the media library to displaying only files contained within my custom folder? If possible, I want the user to be able to choose only files that have been uploaded to the custom folder when interacting with the Media Library instantiated by my plugin.
A solution that works for me is to add a clause to the Wordpress query when the media library is being displayed. From browsing my Wordpress database I noticed that the full path to `wp_posts.post_type = 'attachment'` is stored in the `wp_posts.guid` column. add_filter('posts_where', 'limitMediaLibraryItems_56456', 10, 2 ); function limitMediaLibraryItems_56456($where, &$wp_query) { global $pagenow, $wpdb; // Do not modify $where for non-media library requests if ($pagenow !== 'media-upload.php') { return $where; } $where .= " AND {$wpdb->posts}.guid LIKE '%my-path-segment%'"; return $where; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 5, "tags": "customization, uploads, filters, media library" }
Post not found when filtered by category ID On my home page I am trying to filter by a category type and limit it to one post; but I keep getting "no posts found". Here is my following code: <?php query_posts('cat=34&showposts=1'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Use `post_per_page` instead. Like this: query_posts( 'cat=34&posts_per_page=5' ); Read more about the query on: WordPress Codex
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, query posts" }
How to display html in a shortcode How do you display or process HTML in a wrapped shortcode ? `[myshortcode]<div class="map"></div>[/myshortcode]` my shortcode code is function myshortcode_sc($atts, $content = null) { extract( shortcode_atts( array( 'col' => 'left', ), $atts ) ); $output = '<div class="span' . esc_attr($col) . '">' . do_shortcode($content) . '</div>'; return $output; } add_shortcode("myshortcode", "myshortcode_sc"); is there another function at the return to allow for $output to process the HTML and not just display it as text ?
Maybe try replacing . do_shortcode($content) . with `.$content.` ? Source: <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "shortcode" }
What is the p parameter in a get_posts() parameter array? I've seen code that looks like this: `get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));` What is the definition of the p parameter and is it documented anywhere? I can't find anything about it on the Codex page for get_posts().
'p' is for querying a post, as opposed to 'page_id' for querying a page. It's documented in the WP_Query codex
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "get posts, template tags" }