INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
wp_set_object_terms() -- prevent overwrite? From my understanding (and before trial and error), wp_set_object_terms( 'post_id', 'add_this_term', 'in_this_taxonomy'); But from the Codex, apparently adding the term will overwrite any other terms that are set for that post and that taxonomy? Is this right? What if the terms are nested?
`wp_set_object_terms()` has a fourth argument called `append`. Setting that to true during the call should add the term without unsetting the already set terms. wp_set_object_terms( $post_id, 'add_this_term', 'in_this_taxonomy', true);
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "taxonomy" }
Applying a filter to multiple loops for days ago I'm trying to use a filter that limits the days ago loops pull posts from. My problem is that I need different day limits for certain loops on the index page and when I duplicate the filter over a second loop, I get an error saying "Cannot redeclare filter_where() (previously declared in ".) I remove the filter after the first loop that I use it, but that doesn't help. Here are the filters... <?php function filter_where($where = '') { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string); ?>
Define the filter_where function in your functions.php file in your theme. <?php function filter_where($where = '') { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'"; return $where; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "loop, filters" }
Redirect to post_id? I am using a Simple 301 Redirects plugin and I understand that this requires the redirect to be a permalink. Is there any way I can redirect to a post_id? That way I can move the post (or page in this case) and then I don't have to worry about rewriting the direct URL. Thanks.
The redirection plugin will automatically create a redirection rule when the postname is changed. If you use that (possibly in tandem with simple 301's, though you'd be creating some overhead that way), you can work around it. It should be noted that I have never used simple 301's, but I've used Redirection extensively.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "redirect" }
Querying both pages and posts I am building an "advent calendar" for a client and they are wanting a combination of specific pages and custom posts appearing on the front page, in a specific order. Things that need to be retrieved are Title, Excerpt (or Content up to ), Permalink, Featured Image and Custom Fields... What's the best way to go about retrieving these from the database? A custom SQL query? Some sort of Walker? A complicated Menu?
I ended up specifying the posts, pages and custom posts in a custom Navigation menu, and created a Custom Walker to output the right information.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, menus, query, walker" }
Javascript from Easy-Fancybox place into footer the Easy FancyBox WP-Plugin works fine for me. Just the script will be placed in the header of my source, like other plugin, too. I´d like to push it down to the footer of my website (incl. the inline-script) below jquery-library. Can i fixed it? Thanks Ingo
You can ask the plugin author to update the plugin so scripts go in the footer rather than the header. Or you can look in the plugin code and see this: wp_enqueue_script('jquery.fancybox', plugins_url(FANCYBOX_SUBDIR.'/fancybox/jquery.fancybox-'.FANCYBOX_VERSION.'.pack.js', __FILE__), array('jquery'), FANCYBOX_VERSION); What you can do is edit this yourself so that it enqueues in the footer or you can write a function in your theme functions file that un-queues it and then re-queues it correctly.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, jquery, javascript, footer" }
Show author archive pages for authors with no posts I have one page for each author, but if the author doesn't have any posts I can't get its variables, because the loop is empty. The page returns empty, no avatar, no info and stuff, the whole site is empty. How do I get WordPress to pull out the author variable if there are no posts (what makes no author, but i am on the authors page)..? I'm using twentyeleven as parent theme.
To access the author user object outside of the loop on an author archive, you can do the following: global $curauth; $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); echo 'This is the author page of '.$curauth->display_name;
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "author, 404 error, author template" }
Installing WP twice in same Directory? I have a website that has Wordpress installed in the root directory `/` I have another website, that's contents is within that root directory, `/seperatesite/` that stores a separate, small, splash page type website, with a separate domain pointing to it. I want to setup another Wordpress install inside of this folder. Is it hazardous to have two Wordpress installs setup this way? I'm wondering as I currently don't have the host credentials to create a separate database within the host area if need be, is this simple enough to move without this - or still a sensitive setup? **Thanks for any pointers!**
Have you considered setting your main site to a multisite setup? This would allow you to use the same wordpress files from the root and serve a wordpress site under the `/seperatesite/` directory without the need for duplicating files. take a look at: < If you need any specific help regarding setting this up then feel free to make a new question.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "multisite, installation" }
How to include first assigned category in the post URL? What are the options for creating URLs like: _site.com/category-name/post-name_ Where, "category-name" is the first category that the post was assigned to (in the event that the post is assigned to multiple categories) Note: if the post is assigned to "uncategorized", I don't want to display the category name in the URL, so in that case, I just want _site.com/post-name_ PS: it will also require the removal of the word "category" from the URL. I was able to get that done with the plugin "no category base", however, it does not include the parent category name in the URL to a post.
By default, the category with lowest ID is used. If you want control over what the category is, you can try the Hikari Category Permalink plugin, which allows you to choose which post category is used for the permalink. <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, permalinks" }
Can the Twenty Eleven theme have a Main Sidbar at all? After pulling my hair trying to find out why my Main Sidebar disappeared, I performed as a last act of desperation a complete wipeout of the database and the entire wordpress directory, then I restored them from the earliest backup of my totally fresh install of WordPress, which includes **only the home page and the original sample page** and **no plugins!**. That didn't help displaying the Main Sidebar. But when I switch to `Twenty Ten`, the Main Sidebar, with the calendar in it, is there! This is insane, as I am now beginning to doubt my memory that I ever saw the Main Sidebar on `Twenty Eleven`. Can the Twenty Eleven theme have a Main Sidebar at all? If so, what am I doing wrong?
> Can the Twenty Eleven theme have a Main Sidebar at all? Twenty Eleven Theme does display a sidebar on the homepage, but not on the single posts and individual pages as you can see from the demo of Twenty Eleven. > If so, what am I doing wrong? What's your website URL?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "sidebar, theme twenty eleven" }
Turning Broken URLs Into Search Terms? I'm migrating a Typepad install to a Wordpress subdomain, and most of the links will be broken. The rewrites work so that: is rewritten to If a full link with article information is passed, it is rewritten as such; to I am looking for a way to feed the article title into Wordpress's search so even though the link is broken, it is easy for users with bookmarks find it.
You can try a plugin to do this: < Reads the page URL and tries to find a page/post that it might match and redirect to it. Found out about this plugin from: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "search, redirect, links, 404 error" }
How to show only blog-domain instead of the whole permalink in the loop I wanna show the blog URL instead of the whole post URL in my loop. The reason is that I use Wordpress multiblog with sitewide tags, so on my front-page of the main blog I'm showing the 10 last posts globally. I wanna show the blogdomain the post is coming from. the_permalink works if I wanna show the whole post-url but I need to cut it down to show only the domain. Can anyone help me?
Use `parse_url()`: echo parse_url( get_permalink(), PHP_URL_HOST );
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "multisite, permalinks, loop, subdomains" }
What Defines What Category A Post Picks (if in multiple) If I have a post in multiple categories, what defines what category shows up in the URL? Assuming I have permalinks setup as `/%category%/%postname%` is it the ID or the name?
WordPress always use the category with lowest ID. You can use plugins such as the Hikari Category Permalink plugin to change that however. <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "posts, categories, permalinks, menus, tags" }
Add image URL automatically to custom field? Does anyone know how I automatically add the URL of the uploaded image to a custom field? In other words, When I upload a image I want the url to the image to get a custom field variable automatically so I dont have to add the URL manually to the custom field all the time. I need a seamless integration to make is user-friendly. I want to use scripts like timthumb instead of the built in WP functionality. **\-----UPDATE:** Here is some code I have. Just missing the thumbnail variable in the custom value field. add_action('wp_insert_post', 'mk_set_default_custom_fields'); function mk_set_default_custom_fields($post_id) { if ( $_GET['post_type'] != 'post' ) { add_post_meta($post_id, 'Image', 'I WANT THE THUMBNAIL HERE', true); } return true; }
Here is the final code that adds the thumbnail url to a custom field named Image. function w_thumbnail_src() { if (has_post_thumbnail()) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'emphasis'); return $thumb[0]; // thumbnail url } else { return ''; // or a default thumbnail url } } add_action('publish_page', 'add_custom_field_automatically', 'w_thumbnail_src'); add_action('publish_post', 'add_custom_field_automatically'); function add_custom_field_automatically($post_id) { global $wpdb; if(!wp_is_post_revision($post_id)) { add_post_meta($post_id, 'Image', w_thumbnail_src(), true); } }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "theme development, custom field, images, post thumbnails" }
Hook for writing text string after footer scripts I'm looking to insert a string of JavaScript variables AFTER the in_footer enqueued scripts. When I write the string via the wp_footer hook, they occur before the in_footer scripts. Is there another hook I can tie into that happens after those enqueued scripts have been written.
If you change the priority on the hook to `wp_footer` you should be able to shift when it's called in reference to the enqueue functions. **Example:** add_action('wp_footer', 'my_footer_hook', PHP_INT_MAX);
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "wp enqueue script, footer" }
Wordpress.com Like Button Is there a plugin out there similar to wordpress.com like button? <
Yes, there is. Please check out Gravatar Like.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
User activation in wordpress I want my users to first to activate their accounts so they can use all the features in the site. There is a field in `wp_users` table named `user_status` which its default value is `0`. I wonder what's that field for? Should I use a `user_meta` to indicate the activation status of my users. P.S. The registration of users is handled manually through a plugin I'm writing.
I would use my own usermeta to handle it to avoid having any sort of crossover issues with plugins/future updates. It should also allow you greater flexibility in what you store in the usermeta.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "user registration, user meta" }
WordPress is replacing double minus signs in Post Title, how to disable it? sometimes i have Post Titles that contains 2 minus signs side by side (--) but wordpress is always removing one of the minus sign. Looks like: `My--Text` into `My-Text` any idea how to disable it? Best regards, Chris
yes I believe you can stop that by disabling the wptexturize function: <?php remove_filter('the_content', 'wptexturize'); remove_filter('the_title', 'wptexturize'); ?> ... for example. You can add that to you themes functions.php file. <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "posts, title" }
Adding content to sidebars I am working on a three-column layout where all three columns will have differing content depending on the post/page in the main column. How would I go about giving the ability to change and update the sidebar content and display it in templates using something like `<?php the_content() ?>` ? Since the sidebar content is related to the post I will need a way to reference the right sidebar content for the post. Thanks in advance Yours sincerely, nav
Add a meta box to the post editor, similar to the excerpt meta box, and get the content of the meta box in your sidebar. If you want to reuse the same text on different pages create a custom post type `sidenotes` and add a meta box with a select field to let the author choose the text.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "sidebar, content" }
How do I get the URL of only the first picture in a Wordpress post? How do I get the URL of only the first picture in a Wordpress post? I don't want the URL of the thumbnail, but the first picture in the post loop. I only need the URL for linking purposes. Thanks for your help everyone!
The answer is in Codex. Note that wp_get_attachment_image_src returns the URL of an image's full version if you want.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images" }
Customize individual parts of the list - List Category Posts plugin I was just wondering if there was anyway to customize individual parts of the lists. So for instance if you go to my site at www.r3entertainment.org and check out the Features page, if you look at the top where it says Gaming's Most Memorable Moments.. is there a way for JUST the title link to be underlined and the author to stay normal in each listed post?
You should be able to do it with only a CSS modification: .lcp_catlist a { text-decoration: underline; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin list category post" }
How to automate wordpress installation in subdomain How can I automate the installation of wordpress in a subdomain? Example: Upon registration user1 would get automatically wordpress on user1.domain.com. Then, upon registration user2 would get his own wordpress on user2.domain.com, etc. I can program a little bit PHP, but I would rather avoid any programming and would prefer a ready-made solution if it exists. Thank you in advance for your help. Any hint is appreciated.
Ok, thanks to m0r7if3, I found the two pieces of information I was looking for: * wordpress multisite * "Automatically create a new WordPress site in your Network associated with the user that is created." -> <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite" }
Trying to regain access to a wordpress based website My Dad has a website based on wordpress, he went into the wordpress dashboard and modified the home page incorrectly appending an extra level to it, then when he exited it made changes resulting in website being messed up and more importantly the login to wordpress has disappeared not allowing him to change it back. I manually fixed the url to display the wordpress dashboard login, yet even when login it doesnt work, it takes be back to the wrong page. I don't currently have access to the wordpress database but I do have access to the files generated from the database so my plan was to edit the correct file to set the home page path back to what it should be, hoping that will then allow me to get into Wordpress dashboard. But I have very little knowledge of Wordpress, anyone help me here please.
See Changing The Site URL « WordPress Codex for recovery instructions.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php" }
Max length of meta_value I was wondering if anyone could tell me the max length of the `meta_value` field for posts and user meta.
Both `usermeta.meta_value` and `postmeta.meta_value` are stored as LONGTEXT. Here's how the MySQL docs describe the size of a LONGTEXT data type: > "A TEXT column with a maximum length of 4,294,967,295 or 4GB (232 – 1) characters. The effective maximum length is less if the value contains multi-byte characters. The effective maximum length of LONGTEXT columns also depends on the configured maximum packet size in the client/server protocol and available memory." Source
stackexchange-wordpress
{ "answer_score": 26, "question_score": 17, "tags": "custom field, meta value" }
Change Title Type I'd like to change the title field of a post in admin panel. I'd like this field was "textarea" instead of being "input type='text'". Would it be possible through any hook in functions.php? Thanks in advance!
as this is a default field, i don't think it is possible to achieve what you want with the help function hooks, however you can do this by editing edit-form-advanced.php file inside wp-admin folder, the code you may want to edit is located in line # 291, this is the input type for title field <input type="text" name="post_title" size="30" tabindex="1" value="<?php echo esc_attr( htmlspecialchars( $post->post_title ) ); ?>" id="title" autocomplete="off" /> Do this at your own risk as you are going to edit wordpress core file, once you edit this you might not able to update your wordpress automatically
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "hooks, title" }
If search matches taxonomy Is it possible to redirect the user to the taxonomy page IF the search input matches the taxonomy name exactly? For instance i have a taxonomy called "Actors". If someone put into the search field "Tom Hanks" instead of going to the regular search page, it would redirect them to the taxonomy page for Tom hanks.
I only wanted to match tags in a single taxonomy, so I was able to simplify the code as follows. My taxonomy is 'post_tag' -- just swap yours out as needed. $i = 0; $search_query = get_search_query(); $term = get_term_by( 'name', $search_query, 'post_tag' ); if( $term !== false ) { $i++; $single_result = $term; } if( $i == 1 && is_object( $single_result ) ) { $single_found = true; } else { $single_found = false; unset( $single_result ); } if( $single_found ) { wp_redirect( get_bloginfo( 'url' ) . '/' . $single_result->slug ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "taxonomy, search" }
How-to debug wp_ajax_* hook callback? I'm currently developing a plugin that uses ajax functionality. **Problem:** The callback isn't fired = no data gets processed. if ( ! is_admin() ) add_action( 'after_setup_theme', array( 'wpseAjaxClass', 'init' ), 10 );
The answer was as **stupid** as **simple** : I wrapped the `init` for the class in a `! is_admin()` call. This successfully prevented the callback from beeing fired. ### Rule for AJAX loading * Load it in public * Don't hide it behind a `! is_admin()` call. ### The 2nd line from admin-ajax.php define( 'WP_ADMIN', true );
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "ajax" }
Taxonomy Checkbox Admin Panel I have a basic Admin panel allowing Admin to save options using Checkbox. Checkboxes are used as multiple selection is necessary for the option So, Admin Option \- Checkbox 1 \- Checkbox 2 \- Checkbox 3 etc My Checkboxes are generated on the fly, successfully with `<input type="checkbox" name="firm" id="firm-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( true, is_object_in_term( $user->ID, 'firm', $term ) ); ?> /><input type="checkbox" name="firm" id="firm-<?php echo esc_attr( $term->slug ); ?>" value="<?php echo esc_attr( $term->slug ); ?>" <?php checked( true, is_object_in_term( $user->ID, 'firm', $term ) ); ?> />` Then when saving my option, I am trying to do it with `wp_set_object_terms( $user_id, array( $term ), 'firm', false);` BUt only the last term is saved and not the array (if more than 1 checked) Any idea?
Change the name of the checkboxes from`firm` to `firm[]`. Then, when you go to save the checkboxes $terms = $_POST['firm']; will give you an array of term slugs that can be checked/sanitized prior to using `wp_set_object_terms` to add the terms... wp_set_object_terms( $user_id, $terms, 'firm', false);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "taxonomy, terms" }
Child theme breaks after update of master theme I have a theme, lets call it Master. I manually created a child theme, lets call in Master-Child and added some files into it. All worked well until a notification came that I should update the Master because of a new version. The child theme has failed to work since. I get an error message "Master theme does not exist" although "Master" is activated. I tried to rename, capitalize and lowercase all characters. Thanks a lot.
The only string to use the master is `Template: twentyten` in the style.css if child theme. Check, if this string correct or has the master change this. If you activate the master as Theme in your install, you find the string also in the database of the WP install, in table options, entry `template` and `stylesheet`; if you have active the child theme, must have the entry `stylesheet` your child theme name; the Master is always on `template`. (for fast check this use the plugin Adminer) example screenshot with the Theme "Black Label" as Master, no Child theme used. The Screenshot was in Adminer inside the WP install. !enter image description here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes" }
language support in a custom urdu theme I am planning to start work on an urdu (language in pakistan) website theme. basically, it will be a newspaper themed website. Can anyone tell me how can i add urdu support in my theme. I dont want to change Admin UI language. Just whatever posts/pages I will insert should be in my native language. Any positive ideas will be appreciated. Thanks
Take a look at the files for the default Urdu theme to see what is necessary. WP Polyglots has some information too, the most important changes for 3.4 are listed on a dedicated page. I think the main point are the fonts: Don’t rely on the browsers capability to find the best font file, embed a Urdu font per `@font-face{}` instead.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, language" }
How to have a next page for post? I have a theme installed but my problem is that the theme doesn't provide a next page function. So if I have 20 posts, and I put 10 in the _Blog pages show at most_ in Reading Setting of Wordpress Setting, it only shows the 10 posts and then I can't anymore see the remaining posts on my home because it doesn't have any next button. I want to have a next page button so that the users can still view the other posts by clicking the next button. How can I do this? Need help. Asap! Thank you!
You can use the functions `next_posts_link()` and `previous_posts_link()` for that. You have to place these functions in your theme where you want the links to be seen. Possible templates for that are your archive.php, category.php depending on your needs. <div class="navigation"> <div class="next-posts"><?php next_posts_link('&laquo; Older Entries') ?></div> <div class="prev-posts"><?php previous_posts_link('Newer Entries &raquo;') ?></div> </div> More info: < <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "pages" }
500 error after update I had a working (test) blog, and during an update from 3.2.1 to 3.3.1 - something went wrong , I think the update did not finished.. Just before the Update, I have enabled a new theme (all functions and files made by me ) Since the update went wrong - I can not access my admin area (500 error) but the front end works just fine ... The same blog and theme works without a problem on local machine . I had deleted ALL files on server (except uploads) and updated with a new version - but to no avail. any solutions to such a problem =??
In phpmyadmin search : SELECT * FROM wp_options WHERE option_name = 'template' OR option_name = 'stylesheet' OR option_name = 'current_theme'; then : UPDATE wp_options SET option_value = 'yourthemename' WHERE option_name = 'template'; UPDATE wp_options SET option_value = 'yourthemename' WHERE option_name = 'stylesheet'; UPDATE wp_options SET option_value = 'yourthemename' WHERE option_name = 'current_theme'; or if you want to go back to default (presuming some default exists) SET option_value = 'default' WHERE option_name = 'template'; UPDATE wp_options SET option_value = 'default' WHERE option_name = 'stylesheet'; UPDATE wp_options SET option_value = 'default' WHERE option_name = 'current_theme'; note : * template – the “Theme Name” as defined in style.css * stylesheet – the actual name of your theme folder * current_theme -the actual name of your theme folder
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "errors, updates, 500 internal error" }
category_description() shows raw html after version 3.x? Just looking for some history on the output of category_description() I have categories whose "description" fields are formatted with rich text and I'm trying to understand the differences in WP version with respect to the output of this method so that I can do a version check if necessary to implement desired output. For example, before 3.0.1, it appears that category_description() returned the output stripped of any html markup. However, with the current 3.3.1 release, the output appears to be raw.
Actually HTML is stripped on input, using `wp_filter_kses` function hooked into `pre_term_description` filter. So if this hook isn't removed HTML would be stripped.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "categories" }
Using $_GET variables in the URL? I need to generate a simple error message on a page by passing a variable through the URL. The URL is structured as follows: < I'm sure it's the permalinks rewrite interfering, but I'm not sure how to resolve it.
Try adding the variable to the WordPress' array of 'recognised query variables'... add_filter('query_vars', 'my_register_query_vars' ); function my_register_query_vars( $qvars ){ //Add query variable to $qvars array $qvars[] = 'my_error'; return $qvars; } Then the value of 'my_error' can be found via `get_query_var('my_error')`. (See Codex) **EDIT** From Otto's comment, it's better to do: add_action('init','add_my_error'); function add_my_error() { global $wp; $wp->add_query_var('my_error'); }
stackexchange-wordpress
{ "answer_score": 13, "question_score": 7, "tags": "permalinks, url rewriting, variables" }
Domain name in a WordPress Network I have a domain-based network. Blogs are like: blog1.domain.com blog2.domain.com One of these blogs needs to be migrated to a domain _blog1.com_ , but without leave the network. I know I have to poing _blog1.com_ DNS to _blog1.domain.com_ with a CNAME register (do it), but I don't know what to do now (in other case, not a wordpress network, I'll simply add a _ServerAlias_ to Apache directive, but now I don't have any Apache directive for _blog1.domain.com_ , just for _domain.com_ )
You'll want to use the Domain Mapping Plugin to accomplish this. See the installation tab on that page, it has excellent instructions! Cheers~
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "multisite, apache, dns" }
Programatically changing template of a page Is there a way to change the **Template** of a **page** from **Default Template** to another programatically?
Looking at the wp_postmeta table, you can see the page template is stored there. Therefore, a simple call to `update_post_meta` (codex) should do the trick : update_post_meta( $post_id, '_wp_page_template', 'my_template.php' ); The filename and extension is necessary, as per my example.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "page template" }
How to make WP_Query 'post__in' accept an array? I have a function that returns a comma separated list of post ids that a particular user can access. I want to use this list in a WP_Query loop. The custom function: $array = user_albums(); foreach( $array as $post ) { if( !in_array( $post->ID, $array ) ) $ids[] = $post->ID; } $access_ids = implode( ', ', $ids ); So here is the situation: 1. On my test site the id list is `158, 162, 145, 269`. 2. Inserting the list of ids returns only the first post. `'post__in'=> array( $access_ids ),` 3. Inserting the list of ids not in an array returns an error. `'post__in'=> $access_ids ,` 4. Inserting the post ids manually returns correct posts `'post__in'=> array( 158, 162, 145, 269 ),` **What could I be doing wrong?** I appreciate any help.
`$access_ids` is a string. `post__in` accepts an array. So instead of $access_ids you could use `'post__in'=> $ids` skipping the `$access_ids = implode( ', ', $ids );` all together.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 6, "tags": "wp query" }
Include Drafts or Future posts with count_user_posts? I'm use the code below to get the number of posts by a user and it works fine but it only includes published posts. How can I modify this code or use different code to have it include "future" post_status's or "drafts", for example. <?php $post_count = count_user_posts($curauth->ID); echo '<p>User post count is ' . $post_count; ?>
This will do what you want: $args = array( 'author' => $curauth->ID, 'post_status' => array( 'publish', 'pending', 'draft', 'future' ) ); $posts = new WP_Query(); $post_count = $posts->found_posts; It will include drafts, pending posts, published posts, and future posts. There are more you can set, such as trashed posts, and private posts, but that didn't seem to follow the intent of the question. This method will include custom post types as well as the builtin post types, so additional filtering may be in order. Docs: `WP_Query`
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "post status" }
Should I custom code drop down menus or use a wordpress plugin? **EDIT** \-- Hopefully my question is more clear What is the best practice for wordpress dropdown menus: 1. Custom CSS (editing styles.css) 2. Using a WP Plugin I'm leaning toward coding it myself from scratch, but I don't want to reinvent the wheel if there's a plugin that is standard.
I personally would do the code from scratch method, rather than get a plugin and have to reverse engineer it to do it exactly the way you want it to work anyway. CSS is defiantly the way to go and the web standard as opposed to jQuery/java, by my understanding at least.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "menus, dropdown, sub menu" }
Showing latest post without 301 redirect My WordPress website is now redirected to latest post by adding below function to `function.php` add_action( 'template_redirect', 'redirect' ); function redirect() { $args = array( 'numberposts' => 1, 'post_type' => 'seller', 'post_status' => 'publish'); $last = wp_get_recent_posts($args); $last_id = $last['0']['ID']; if ( is_home() && ! is_paged() && ! is_archive() && ! is_tag() && !isset($_GET['ptype']) ) : wp_redirect( get_permalink($last_id) , 301 ); exit; endif; } now, I want this feature but without changing URL to latest post! I mean when you go to < latest post shows **without a 301 redirect** to <
Custom query loops and custom page templates are your friends. Ditch the redirect function and on your home page template do something like this: <?php $args = array( 'post_status' => 'publish', 'post_type' => 'seller', 'posts_per_page' => 1 ); query_posts( $args ); // the Loop while (have_posts()) : the_post(); the_content( ); endwhile; ?> You can find all args here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, themes, templates, redirect" }
Information and Videos for Customers in the Backend I am looking for ideas or plugins that would allow me to have a backend area for clients to log into my site and access files specifically assigned to them. I provide video IT help files for clients which contain information specific to their setup and would also like to have the ability to offer or accept files from them through this backend (files that would never make it through email). Does such a backend plugin exist? Thanks in advance stack!
Try Justin Tadlock's members plug-in. You can then create custom roles per user in the _Users/Roles/Add New_ section of the WP-Admin Area. Once the role is created, you can add custom capabilities. I've never tried the email option you've mentioned, but it's possible. If you go this route I'll try to help you figure it out.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, plugin recommendation, profiles" }
Graphic design changes on Staging before moving to Production? I have a Development, Staging and Production workflow for my WordPress site. I am fairly strict about any structural work to be done on the site being done in Staging first, then migrated to Production. I feel some changes may be better done on Production through the admin interface, such as a simple logo change, and some may be better done on Staging then migrated up to Production, such as a theme alteration. Where do you draw the line? What changes would you allow directly on the Production site and what changes would you say have to be done on Staging before being migrated to Production, for safety's sake?
I make sure the structure (page-title, categories, custom-post types) have the optimal headings and correct structure before migrating. Small changes such as a logo or minor graphics shouldn't effect the quality of the website once moved to production.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "design, staging, workflow, production" }
How to use Jeditable plugin with admin-ajax.php? Jeditable is saving data to the file like: $('.edit_area').editable(' { type : 'textarea', cancel : 'Cancel', submit : 'OK', indicator : '<img src="img/indicator.gif">', tooltip : 'Click to edit...' });` How do I replace JQuery.ajax with admin-ajax.php? Do I just replace < to admin_url('admin-ajax.php')?
I found a solution for my question. This plugin works with url formatted like: $('.edit_area').editable('<?php echo admin_url('admin-ajax.php'); ?>?action=youraction', { type : 'textarea', cancel : 'Cancel', submit : 'OK', indicator : '<img src="img/indicator.gif">', tooltip : 'Click to edit...', somekey : 'somevalue' });`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "ajax" }
Wordpress 2.7 upgrade protocol I have been entrusted with this site < and it's running wordpress 2.7. It's theme is a custom designed theme and hasn't had any plugin updates since about 2010. I am hesitant to update anything until I know if and/or how it can be done. Will I need to source every version from 2.7 and update one by one? Should I export all posts etc and try and recreate it in 3.3? Essentially how to get 2.7 to latest
Copy the entire site – including the complete `wp-content` and the data base – to a local server and run a test. There is no other way to know if it works. Usually you can run the automatic upgrade from any version of WordPress. Outdated themes and plugins are not safe.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "upgrade, wordpress version" }
Create entire wordpress as a github repositery? In my IDE (Flash Builder for PHP), I can't find a way to create sub project inside Wordpress project as I did with NetBeans. Seems I need to make entire WordPress as a github local repo in order to add version control for my small plugin. Is there other ways I can import git repo as a project inside main project?
There are two ways to make this easier: 1. Set WordPress as a separate project and associate it with your current sub project as shown in this answer. 2. If 1. isn’t possible manage the Git repository from a terminal and don’t use the limited build-in Git manager in Flash Builder.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, plugin development, git" }
Plugin for loading comments on-demand Is there a plugin which would allow visitors to load comments when they want to, rather than always showing them by default? Preferably through an AJAX call or something to prevent page reload. I'm thinking a nice and visible link or button with `View n comments` or something along those lines. Hope I'm making sense :)
A solution oriented around users without javascript: 1. Apply a wrapper `div` to your comments, leave everything else (including CSS as is) 2. On page load, use javascript to hide the wrapper and display a link or button or something for 'view comments' 3. onclick 'view comments', fade/slide the comments in. The advantage to this is that your comments will still be visible to those not using javascript (specifically: search engines), but it will behave exactly like it would if you made the changes in the CSS.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin recommendation, comments, ajax" }
ABSPATH in Windows I'm having a a pain in the head using the `ABSPATH` constant in Windows. Addressing files and folders in Windows is usually done using the `\` (forward-slash) character while for Linux the character would be `/` (backslash). Unfortunately the `ABSPATH` in Wordpress is defined with only Linux in mind (putting a `/` at the end of it). I wonder if I can over-ride it's definition since in `wp-config.php` it's defined under an `if` clause which indicates it can be defined elsewhere. **Problem detalis:** 1. I'm running on `localhost` 2. The problem is with the `statpress-visitors` internal addressing. This is how it addresses the files: ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/def/os.dat' And this is what I get as output: C:\wamp\www\wp/wp-content/plugins/statpress-visitors/def/os.dat
Windows does support both styles of slashes in path. I am not sure if `ABSPATH` definition is safe to edit: * _pro_ it's in `wp-config.php` * _con_ it's says to not edit following above it Myself I just use it as is, or replace slashes to make them uniform when putting path together. If that doesn't work for you please provide specific examples where this causes issues.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "constants" }
Exclude stylesheet from admin I have been using the following function to enqueue some CSS to my theme. However, they are used in the admin area as well: wp_enqueue_style(...) I don't want them to be used in the admin area. Sadly I cannot find anything about that neither here nor on Google in combination with this function. The codex doesn't explain it as well and the function does not support an option to apply to a specific style the exclusion of the admin area. I hope somebody could tell me how to exclude a specific css from the admin area. Thanks in advance.
There are a couple of options. One is to wrap the enqueue in a check to see if it is the admin. if(!is_admin()) wp_enqueue_style(....); The other is wait to enqueue the style until template_redirect. function my_enqueue_styles() { wp_enqueue_style(....); } add_action( 'template_redirect', 'my_enqueue_styles' );
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "themes, admin, css" }
Wordpress: Remove link in the_tags How do I remove the link generated by the_tags? This is what I use today: `<?php the_tags( '', '', '' ); ?>` That results in the tags assigned to the post. But I want to remove the link. Any idea?
Use following code: <?php $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { echo $tag->name . ' '; } } ?> More details: <
stackexchange-wordpress
{ "answer_score": 5, "question_score": 1, "tags": "php" }
Importing WP settings to another host I am doing development and testing of a WordPress site on my local machine and have tweaked the WP settings accordingly using the GUI. Installation of WP on my host is easy however, I do not want to go through the GUI and setup everything from the beginning and would like to just import the settings from my local machine. I know that there is an import/export function in WP but this is only for importing and exporting WP content not WP settings. So what would be the best method to import the settings. Thanks in advance. nav
Follow the steps: 1. Copy/Move all files to new location 2. Export database from old mysql server and import data in new server (you can use phpmyadmin for that) 3. Select wp_options table using phpmyadmin from new location. 4. Edit 2 entry in option table with option name home and siteurl . set option value = new location url 5. Login to wp-admin. 6. Go to setting >> Permalink and update permalink structure if you were using that on old location 7. And you're done. Your new site is live now. Source: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "options" }
WP-e-commerce (getshopped) - Annoying permalink issue i’m using wp-ecommerce (getshopped) and WPML on a website, all pages display correctly when i use the default (/ugly…) permalink structure, but when i try to use the much desired permalink structure /%category%/%postname%/ something weird happens: 1. product categories list page displays the homepage 2. single category and single product pages show the main blog page (list of post) This prevents me from using my desired permalink structure, which is a major issue for me. I tried updating WPEC to the latest beta version (didn’t help) and i tried switching to twenty ten to see if the problem is related to my theme (and it isn’t) Questions: 1\. Could this be related to the fact that i use hebrew words in my slugs? 2\. Is there any known issues related to WPEC and permalinks that i should be aware of? 3\. Can anyone point out the solution? Thanks in advance
Apologies, I find this a little bit a non-issue as it states clearly everywhere that WPML works 100% when you use a permalinks structure of day and name ( If this is something you cannot accept, then you's better come to terms with the fact that WPML most likely is not going to work 100% for you. Or, to answer your questions: re 1. no, this has nothing to do with the fact that you use Hebrew words in your slugs re 2. no, there are no other known issues related to WPEC and permalinks that you should be aware of re 3. the solution is to use a permalinks structure of day and name (
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, url rewriting, 404 error, plugin wp e commerce, plugin wpml" }
Custom Post type - how to get checkbox to update meta field to null I have 7 meta fields for a custom post type in Wordpress. These 7 in particular are days of the week (Sunday thru Saturday) and have checkboxes for each. I've successfully gotten the checkbox to POST when the value is "On", however when I return to the edit page and try to deselect, the value stays the same in the database. Here is what I have for each item input: <li><input type="checkbox" name="sunday" <?php if( $meta_sunday == true ) { ?>checked="checked"<?php } ?>" /> Sunday<br /></li> And my update lines: if(!isset($_POST["sunday"])): return $post; endif; update_post_meta($post->ID, "sunday", $_POST["sunday"] );
It appears the post meta is not being cleared for 'sunday' when the checkbox is unchecked. If( isset($_POST['sunday']) ){ update_post_meta($post->ID, "sunday", $_POST["sunday"] ); }else{ delete_post_meta($post->ID, "sunday"); } return $post; Or you can set the value to false If( isset($_POST['sunday']) ){ update_post_meta($post->ID, "sunday", true ); }else{ update_post_meta($post->ID, "sunday", false ); } return $post;
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "custom post types, post meta" }
Remove width and height attributes from [gallery] output WordPress automatically adds the width and height attributes to [gallery] shortcode images. How to delete these attributes? Something like this but for [gallery] output.
I can think of a couple of options: 1. Create a new shortcode, e.g. my_gallery. You can copy the code in `wp-includes/media.php`. Look for the code staring with `add_shortcode('gallery', 'gallery_shortcode');` and then the actual function. Rename / modify as needed. The actual img link is within the `$link` variable 2. Use something like this (untested), which should work but might strip-out **all** width/height from any link. _ add_filter('wp_get_attachment_link', 'remove_img_width_height', 10, 1); function remove_img_width_height($html) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "shortcode, gallery, customization" }
Remove Save Draft & Preview Buttions.. and also Statius: Draft & Visibility: Public I want to remove the entire section that says Save Draft, Preview and Status: Draft and Visibility: Public. I want to not show it. Its ok if it is still fuctional. Attached is the part I do not want to display. Can someone show me how to do it? Here is the area I want to not display: <
You can hide them using CSS. Add this to the theme's functions.php file, or add a plug-in header to the top of the file and zip it up to use as a plug-in: <?php add_action('admin_print_styles', 'remove_this_stuff'); function remove_this_stuff() { ?> <style> #misc-publishing-actions, #minor-publishing-actions { display:none; } </style> <?php } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "buttons, draft, customization, post status" }
Rewrite wp-login.php URLS to static pages? I'm struggling with getting a few things in WP to redirect. I'm using a front-end profile / profile editor, and I'm also using a front-end login/register. Naturally I would like to redirect the standard wp-login.php URLS to specific ones. Mainly : ` => ` => ` , , etc => I've tried to use RewriteRule's in my .htaccess file, namely : `RewriteRule ^login$ [NC,L]` to test out rewrites, and nothing happened. I have also been somewhat unsuccessful with `add_rewrite_rule()` If anyone could point me towards the right direction, it would be much appreciated! Thanks, Tre
Ozh has a great tutorial about pretty login URLs, that you might find helpful - Pretty Login URL: a Simple Rewrite API Plugin Example
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "url rewriting, rewrite rules, mod rewrite" }
Plugin temporary files and files to download via FTP What is the best place to store temporary files for WP plugin which are not necessary for the future? And what is the best place to store files which will be downloaded via FTP?
You could create your own file in wp-content and reference it like so: $cache = content_url(); $cache .= "/cache/" That _should_ echo ` so you can run all your operations off of that, like systematically clear it. Do the same for downloads if you want them to be distinct.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "plugins, plugin development" }
Exclude post format from get_posts The title basically says it all. I know I can use the following to get posts from the `aside` post format: $args = array( 'post_type'=> 'post', 'post_status' => 'publish', 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-aside' ) ) ) ); $asides = get_posts( $args ); foreach ( $asides as $aside ) { setup_postdata( $aside ); // HTML... } What I would like to know is **how do I get posts that are _not_ in the `aside` post format**?
You just need to set the `operator` parameter to `'NOT IN'` (see Codex on tax queries). Untested, but for your purposes: $args = array( 'post_type'=> 'post', 'post_status' => 'publish', 'order' => 'DESC', 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-aside' ), 'operator' => 'NOT IN' ) ) );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "get posts, loop, post formats, exclude" }
Is it possible to run plugin code when a multisite blog is deleted? I have a plugin that creates tables when activated or when a new blog is added to a network. When a blog is deleted I would like to be able to remove those tables for that blog. Is there a hook available to do this? I imagine it would be something similar to wpmu_new_blog, but I can't find an equivalent for deleting.
The function `wpmu_delete_blog` in `/wp-admin/includes/ms.php` has an action hook called `delete_blog`. This hook passes the variable of `$blog_id` You could try plugging into that hook, although it is executed right at the beginning of the function.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, multisite" }
How to get the clean permalink in a draft? When I use `the_permalink` or `get_the_permalink` in a draft or scheduled post, the URL provided is not the "final" permalink—it is the unpretty `?p=xxxxx` version. How can I get the final, "clean" permalink to show up in a draft or scheduled post? I could do something involving `$post->post_name`, but I'd need the path as well, and that varies from post type to post type and depends on permalink structure. Is there a "universal" way to do this?
This is a little "hacky", but when you call `get_permalink` and you need the permalink for a draft, provide a clone of your post object with the details filled in: global $post; if ( in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) { $my_post = clone $post; $my_post->post_status = 'publish'; $my_post->post_name = sanitize_title( $my_post->post_name ? $my_post->post_name : $my_post->post_title, $my_post->ID ); $permalink = get_permalink( $my_post ); } else { $permalink = get_permalink(); }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 6, "tags": "permalinks, template tags, draft" }
Compatibility of MathJax extension and JetPack I just installed the MathJax Extension for Wordpress because I did not really like the way the math were rendered with the `[latex]` tags provided with the JetPack. If I use the classic `$$`, the blog renders the equation using MathJax. However, if I keep using `[latex]` the JetPack function seems to be used, and I can't find a way to only remove this feature from the jetpack? Is there any known issue in having the two methods at the same time? Is there a way to remove only this feature from the jetpack?
Remove.") Jetpack’s shortcode handler: remove_shortcode( 'latex', 'latex_shortcode' ); I don’t know when exactly the shortcode is registered, you have to find the best execution point (action) to remove it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "shortcode, plugin jetpack, plugin mathjax" }
Variable use in get_template_part As far as I understand (from the get_template_part codex) `get_template_part` is just a wrapper round the PHP require function. So if I have a variable that I have create in a page template file e.g. `$message`, I would have assumed you could directly use that variable in the template part So in template file: <?php $message = 'my message'; get_template_part('messages'); ?> Then in template part messages.php: <?php echo $message; ?> However the echo will display nothing.
D'oh, it just needs a `global` as its inside a function. messages.php: <?php global $message; echo $message; ?>
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "page template, get template part" }
Moving wp-content outside of web root? Is it possible to move the entire wp-content folder outside of the Web root? I need to prevent anyone to view any asset file (images, pdfs, movies etc) with a direct url to the file... Any ideas? Or could I do this safely with htaccess?
See Ben Word - How to Hide WordPress ### _Summary:_ > In the Roots Theme we’re taking several steps to help make it not so obvious that you’re using WordPress: > > 1. Cleaning up the output of `wp_head` and removing the generator from RSS feeds > 2. Hiding `/wp-content/` by rewriting static theme assets (CSS, JS, and images), rewriting the plugins directory, and also changing the location of WordPress uploads > 3. Cleaning up the output of navigation menus with a custom walker > 4. Bonus: root relative URLs >
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "urls, htaccess, filesystem, wp filesystem" }
Run query_posts if SESSION is empty? I am having trouble running query_posts when my page loads for the first time, i.e Session is empty. When the page loads for the first time and the SESSION is empty, the following code runs: <?php $id = 106; if ((empty($_SESSION['r1']))){ echo "This Line Prints"; query_posts("cat=-.'$id'&".$query_string); wp_reset_query(); echo "This Line also Prints"; } ?> The two statements mentioned in the above code are printing but the query_posts is not running here. However when I am running it outside the session it is working fine :S How can I run this query_posts if the Session is empty? Why doesn't this code work?
if ( empty($_SESSION['r1']) ) { global $query_string; query_posts($query_string . "&cat=-" . $id); } This should work, depending on $id is set.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, query, session" }
hiding permalink in admin if the user is subscriber I don't want to show the permalink if the user is subscriber. Can anyone help me to achieve that? PS: I'm talking about the permalink which appears `below title` while creating new post. PPS: I modified the rules for subscriber. They can able to submit the post for review
function hide_slug_box() { global $post; global $pagenow; if (is_admin() && $pagenow=='post-new.php' OR $pagenow=='post.php') { echo "<script type='text/javascript'> jQuery(document).ready(function($) { jQuery('#edit-slug-box').hide(); }); </script> "; } } add_action( 'admin_head', 'hide_slug_box' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, permalinks" }
Settings API - changing add_settings_field() output? I'm using Settings API and wondering if there's any way of editing default output of add_settings_field() function? add_settings_field('the_field', 'bar', 'foo', 'page', 'section'); function foo() { echo 'foo'; } Outputs: <table class="form-table"> <tr valign="top"> <th scope="row">bar</th> <td>foo</td> </tr> How to get rid of these table tags and replace them with something else?
If you look at `do_settings_fields()` (line 1125, `/wp-admin/includes/template.php`), you can see that the table information is hardcoded into the the settings API. If you wish to not use the table, you will need to develop your own settings functions.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "options, settings api" }
How to query posts with certain custom meta data, and output Post data I've been working on modifying the Thesography plugin to include the Google Maps API. So far I've had success doing so. I'm looking to take this one step further and have 1 large Google Map that would display all of my images on 1 map. Then when you hover over a marker, an image thumbnail comes up with the post title. I know the requirements for the Google Maps API to make this possible, but am struggling with trying to get the data out of MySQL. I'm looking for some coding help that'll help me extract the following information from a post, IF it has "latlng_readable" in the post_metadata. For the Google Map, I'd like to be able to grab the post title, the post image URL and the "latlng_readable" meta coordinates for the marker pin. This way I can put this into the Google Maps API so that in the popup box for my marker is a little thumbnail of the image, as well as the title of that image.
Trying using `WP_Query()` using the `meta_query` arguments. Something like this: <?php $geotag_post_query_args = array( 'meta_key' => 'latlng_readable' ); $geotagged_posts = new WP_Query( $geotag_post_query_args ); ?> Now, `$geotagged_posts` is a query object, that should include all Posts that have the `latlng_readable` meta field. You can extract the `$post` data from this object the same as any other query object.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom field, post meta" }
Add a button to tinyMCE editor on Custom Post Type How do I go about adding a simple button to tinymce on the default editor area of my new Custom Post Type? I'd like the button, when clicked, to ask for a text value. The script should then `lowercase` the input and replace spaces with hyphens, and insert `[glossary=value-entered]` into the editor. Thanks in advance,
Check out this tutorial on Pro Blog Design: <
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "tinymce" }
When replacing #site-title with an image - why must it be located in root? I needed to replace the `#site-title` text with an image and I found a great blog post explaining this: < But it appears that the image to be placed in `background: url(/header.png) #fff no-repeat;` must always lie in the root directory (`~/public_html`). I am using a Twenty Elven **child** theme and I tried to place the image file in the `images` subdirectory of the child theme, but when I do this no image is visible. So far, the solution described in the article only works if the image is placed in the root directory. Why is that? Is there a way to allow the image to be placed in the images subdirectory of the child theme?
The / in header.png makes it look in the root directory. Try just doing `background: url(header.png) #fff no-repeat;`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, theme twenty eleven" }
BuddyPress user bio in profile I am trying to figure out how to have a user bio in the user profile using BuddyPress. For example, on this page < where it says "I help lead the BuddyPress and bbPress projects. I also like puppies, potato chips, and a good nap." I'm assuming it's default behavior since it's on the BuddyPress site, but if it's not, that might be why I'm having issues. Is that a BuddyPress plugin? How can I get that implemented?
I ended up adding a User Bio Profile Field and then displayed it by inserting the following into member-header.php in the BuddyPress theme files: <?php if ( bp_get_profile_field_data( 'field=User Bio' ) ) : ?> <div class="user-bio"><?php bp_profile_field_data( 'field=User Bio' );?></div> <?php endif ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "buddypress, profiles" }
Multiple Galleries in WordPress 3.3.1 There are a good plugin, that allows user to make several galleries in one post not using manually "include" attribute. < But after upgrading on 3.3.1 core version of WordPress this plugin don't work anymore. (I suggest this is because of changes in file post manager.) Does anybody know the way to fix that? Maybe there is another plugin that realize this function?
Use Nextgen and problem solved. You can add as many galleries as you want. And you're right, sadly, this core upgrade killed a lot of amazing plugins. I have downgraded sites because of that.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "gallery" }
User needs to login first before accessing website _**In my application, users have to login first before accessing the website._** So now what I am doing, I have created one custom login page. How can I redirect a user to the login page if he/she is not logged in yet. Should i customize wp-login.php for login? Which is better way, **1.** Redirect user to login page or **2.** wp-login.php
You can use the following action to redirect all traffic to that login page. You will need to specify the page name and the page slug. add_action('wp', 'wpse_41699_wp', 0); function wpse_41699_wp(){ if(is_page('Login')) return; if(!is_user_logged_in()){ $url = get_bloginfo('home').'/login'; header('HTTP/1.1 403 Forbidden'); header("Location: $url"); exit; } } Also, you can download the plugin version for this answer here.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "login" }
is_page() or is_single not working Im trying to clean up my scripts and I'm using a function to but ran into a problem with using both !is_page or !is_single to only show certain scripts on singles and pages. What did I do wrong here. add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 ); function my_deregister_javascript() { if ( !is_page() ) { wp_deregister_script( 'thickbox' ); wp_deregister_script( 'shutter' ); wp_deregister_script( 'swfobject' ); wp_deregister_script( 'ngg-slideshow' ); wp_deregister_script( 'ngg_script' ); wp_deregister_script( 'jquery-shuffle' ); } elseif ( !is_single() || !is_page()) { wp_deregister_script( 'autosize_js' ); wp_deregister_script( 'admin_js' ); } }
The problem is probably because `wp_print_scripts` is too late to deregister scripts as this is when they are outputted to the template. You should consider using `wp_enqueue_scripts` or `wp_register_script` instead. This question may help: wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i'm confused
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions, conditional tags" }
Can I change ownership of my plugin? By adding a new committer and removing the original committer can I effectively change ownership of plugin? I would like to transfer a plugin to a new wordpress.org profile. I am the author.
As of 2015 you can do this yourself, and you don't have to email anyone. Go to your plugin page (example: < ) and click on the ADMIN button on the right hand side. On that page, add the new person as a committer and remove yourself. Then update your readme and plugin files to point to the new USER ID and check the code in. You do not need to bump your version numbers. Done :)
stackexchange-wordpress
{ "answer_score": 12, "question_score": 7, "tags": "plugins, wordpress.org" }
Is there a seamless solution for submitting plugins to wordpress.org SVN and GitHub? > **Possible Duplicate:** > How-to: push a GitHub repo to the wordpress plugin servers I love WordPress, but I also love GitHub. Would love to know if there is a seamless solution to using both SVN and GitHub for plugin development?
The wordpress plugin repo does not have any API as far as I can tell for push and pull hooks from a 3rd party service like github. Right now the solutions are hacky at best and require you to use git as a middle man (on your computer) and also deal with SVN's use of tags/trunk/branch which git doesn't like very much. It's not very fun or seemless, more along the lines of "can I actually do this", at least for the moment. < <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "svn, github" }
How to enqueue jquery in admin and why is it not already there? Why does the jquery below not fire? Its going to the "else" every time. if ( is_admin() && $pagenow == 'theme-install.php' && $_GET['tab']=="upload"){ add_action('admin_print_scripts', 'theme_upgrade_alert'); function theme_upgrade_alert(){ wp_enqueue_script('jquery'); echo ' <script type="text/javascript"> if(typeof jQuery!="undefined"){ jQuery.noConflict(); //jQuery(document).ready(function(){ jQuery(".install-help").hide(); //}); } else { alert("If you are attempting to upgrade the current theme, you must do it via theme options."); } </script>'; } }
First, check for syntax errors. The syntax highlighting seems to indicate that you have syntax errors. Second, don't wrap your `add_action()` calls inside conditionals; rather, wrap your _callback function content_ inside the conditionals, e.g.: <?php function theme_upgrade_alernt() { if ( is_admin() && $pagenow == 'theme-install.php' && $_GET['tab']=="upload"){ // CODE GOES HERE } else { // ELSE CODE GOES HERE } } add_action('admin_print_scripts', 'theme_upgrade_alert'); ?> I would also recommend enqueueing your scripts at `admin_enqueue_scripts`, rather than `admin_print_scripts`.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 0, "tags": "jquery, wp enqueue script" }
How can you change the 'Insert into Post' title in the media button? Actualy the question says it all. I integrated a media upload box to my admin page and a button with the text 'Insert into post' makes no sense. I rather like to change it to something like 'Use this image'. Anyone got a clue on how you are able to do so?
add_filter("attribute_escape", "myfunction", 10, 2); function myfunction($safe_text, $text) { return str_replace("Insert into Post", "Use this image", $text); } Place in your theme functions file of in a plugin file. The first usable filter that this button hits is on the function `esc_attr()`. So what that code will do is find any instance of `Insert into Post` that is run through `esc_attr()` and replace it to `Use this image`. This code might have undesired issues elsewhere though. Maybe there is a language file method someone might know of that might be a better solution than this. **TRY:** add_filter("attribute_escape", "myfunction", 10, 2); function myfunction($safe_text, $text) { return str_replace(__('Insert into Post'), __('Use this image'), $text); } Should account for translations.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "posts, media, buttons" }
is_front_page only works in theme file, and does not work in functions.php If I use is_front_page() in my front-page.php file it works as expected. However if I use the same function in my theme functions.php file it does not work. Is this normal behavior? If not can it be trouble shot somehow? In settings->reading I have my front page set to a page called "front page" so I think that is all set. **EDIT** adding the following to functions.php does not work, however I promise it does work as expected if I add is_home_page() to my header.php file add_action('init', 'my_test'); function my_test(){ if(is_front_page()) echo 'is it?'; }
That may be normal behavior, depending on how exactly you're using `is_front_page` in your functions file. If you use it inside the global scope of `functions.php`, it will not work. Why? Because WordPress loads `functions.php` before the `$wp_query object` has been set up with the current page. `is_front_page` is a wrapper around around `$wp_query->is_front_page()`, and if the query hasn't been set up, it's always going to return false (or throw a warning, if you have `wp_debug` on. From the codex: > Warning: You can only use conditional query tags after the init action hook in WordPress. For themes, this means the conditional tag will never work properly if you are using it in the body of functions.php, i.e. outside of a function. <
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "themes, frontpage" }
Ajax takes 10x as long as it should/could I have just hit my first serious issue with WordPress and for someone that enjoys Ajax this is a biggy. I have an Ajax request that is taking 1.5 seconds to complete while using the Ajax API. If I take the same exact code and run it with a custom script(no WordPress) the Ajax request takes merely 150 milliseconds. **This is not an exaggeration** If you look at the very first comment of < and the conversation that follows you will see that this slowness is caused by the fact that on your request, all of WP is loaded... I am hoping that there is a solution out there that will make it possible to make Ajax requests while not loading all of WordPress. What are your experiences with speeding up Ajax requests with WordPress?
Yep, this is nasty issue that to have full WordPress environment you need to spend considerable time loading it. I've needed much better performance (for very dynamic incremental search feature) for work and what I went with is: 1. Custom file as Ajax handler. 2. SHORTINIT constant for limited WP core load. 3. Very selectively loaded parts of core, only those needed for the task. This provides very limited environment, but performance is way way better and reasonable degree of compatibility with WP (starting with `$wpdb`) is retained. Here is start my loader file, not pretty but works for specific needs: <?php ini_set('html_errors', 0); define('SHORTINIT', true); require '../../../../wp-load.php'; require( ABSPATH . WPINC . '/formatting.php' ); require( ABSPATH . WPINC . '/meta.php' ); require( ABSPATH . WPINC . '/post.php' ); wp_plugin_directory_constants(); // stuff goes here
stackexchange-wordpress
{ "answer_score": 63, "question_score": 55, "tags": "ajax, performance" }
Behind-the-scenes HTTP Request? I'm trying to add a line to my functions.php that does a behind-the-scenes HTTP request submitting some user information to a mailing list URL I have. I'm trying to test the code at the moment, but nothing seems to be working. I have tried the following: $url = 'blabla.org/mailinglist/add?' . $user_email; $request = new WP_Http; $result = $request->request($url); and wp_remote_post($url); Neither have worked. However, if I Just copy and paste the URL into my web browser, it works fine. Please help! Thanks, Tre
Only use `wp_remote_post()` if you are actually posting something. Try using `wp_remote_get()` with a full url $url = ' . $user_email; $results = wp_remote_get( $url ); // var_dump( $results );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "http api" }
Search everything (posts, pages, tags, cpt, meta) I would like to know how to use the built in wordpress search to return results from all content on my site. Specifically, I want to search; * posts * pages * tags * custom post type (portfolio) * custom taxonomy used in custom post type (skill, client) * metaboxes used in custom post type (portfolio_caption, portfolio_excerpt, portfolio_credits, portfolio_links) I would like one search form and don't need to limit the search to certain post types or categories. Just enter the search term > click search > see matches from all content on my site. Simple ;) Update: Preferably, I would achieve this through a function or custom database query rather than using a plugin. This is because I'm developing a theme and want this functionality included out of the box rather than requiring a user to download a plugin. (title changed)
DeluxeBlogTips.com 1) has an article on how to do combined searches in both posts and meta data. Basically, it involves two queries via the $wpdb object; one to search the meta table to get a list of `post_id`s and the other is a query of posts to get `post_id`s. You then merge the arrays and use that to do a query with a `WP_Query` using the `posts__in` argument. Using tags may be a bit tricky because 1. tags are meant to group posts together and 2. tags and taxonomies involve 3 different tables. 1) The linked article is not completely right. It should be `$keyword = "%".like_escape( $keyword )."%";`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "custom post types, custom field, functions, search, post meta" }
Show Blogroll of another WordPress site I am managing a couple of WordPress sites, all hosted on the same VPS, and the client would like the homepage blogroll of `Site A`, that the own, to appear on `Site B` that the also own with the same Author attribution, preferably to link to the originating sites author as opposed to a duped author on `Site B`. I was thinking of either querying the database on `Site B` with a replica `query_posts()` query however I am having trouble reverse engineering the `query_posts()` function. Is there a way to do this for an 'external' site? NB; sites are not `multisite`. I tried that but it all dropped off and a critical plugin we need is not compatible.
You have a couple of options here, but first let me advise you away from querying the database directly. If your sites are _that_ closely related, then they should be in a Multisite network ... # RSS On Site B, fetch the RSS of Site A and display the posts and author attributions there. You can find any number of RSS plugins that do this for you or just get you started. # XML-RPC Site B can also connect to Site A to fetch the latest posts using XML-RPC. You then have full access to data, including the most recent posts, as well as media, comments, etc.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "query posts" }
plugin_dir_url() adds path to url For some reason I get the following output from var_dump( plugin_dir_url( __FILE__ ) ); > < in a local install. Note: I deactivated **all** plugins and added the line on top of the `functions.php` file of the default and unmodified TwentyEleven Theme
There is `plugin_basename()` call some levels inside which seems to use `WP_PLUGIN_DIR` and `WPMU_PLUGIN_DIR` constants, so my guess would be this function is only meant to be used for things inside plugin directories and not other places like theme.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 2, "tags": "plugin development, plugins url" }
Get the current hierarchy php page Does exist some way to get the current searched hierarchy php page in `Wordpress`? I've set a default category to my posts named `post` so if I digit ` which php page is searched in the `hierarchy`? It would be great to get the current page searched.
Assuming that you're wanting to determine which _template page_ is currently being displayed, within the _template hierarchy_ , the easiest way to do so is via the output of `body_class()`. However, if you need to return this information programmatically, the easiest way might be to call `get_body_class()`, and then evaluate the array of classes returned. Given the way that `get_body_class()` steps through each query conditional itself (and the template loader does likewise), I'm guessing that core doesn't have a more abstracted approach.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -3, "tags": "template hierarchy" }
Define a name to the posts slug I would like to use the url ` for my posts and I've saw in my admin page I have the current url ` obiouvsly incorrect. How can I define the slug for my default posts? I'm using various custom post types so I would like to name the default posts simply to `post`, is it possible?
Set your permalink structure to custom and use: /post/%postname%/ Then when registering your custom post types use something like this: 'rewrite' => array( 'slug' => 'something', 'with_front' => false ), Using `with_front` set to false will make sure that your new custom post types don't share the `/post/` part of your permalink structure
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "posts, slug" }
Echo all API Settings sections? Is there a WordPress function displaying all sections registered with add_settings_section()? I was thinking about SQL query maybe, but have absolutely no idea how and where these are stored, couldn't find them in my database.
Use the `$wp_settings_sections` global. It returns an array of settings sections.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "settings api" }
Bulk theme settings in wordpress multisite I have a multisite with 500+ subsites. I would like to install the same theme in all 500+ sites. Most of them requires configuration like selecting sidebar(left/right), Selecting primary menu etc. Is there any plugin available to do this job? OR Can anyone give me some idea? Thanks
If you configure your Theme settings code properly, the Theme will work fine without having any user-defined settings. The key is to define a defaults array, and anytime you need to output a Theme option, run an `array_merge()` on the defaults array, and the theme's options DB entry. Something like this: <?php global $mytheme_options; $mytheme_options = mytheme_get_options(); function mytheme_get_options() { // Defaults array, defined elsewhere $option_defaults = mytheme_get_option_defaults(); // Return parsed args $options = wp_parse_args( get_option( 'theme_mytheme_options', array() ), $option_defaults ); } ?> Then you only ever use the globalized `$mytheme_options`, which will always contain either the default option, or the user-defined option, if defined.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "multisite, options" }
Insert "New User" and update/set meta data at once The wordpress function wp_insert_user doesn't seem to set (overwrite) the input I give. (documentation shows you can't) Trying to use: wp_insert_user using the returned userID also doesn't work. Of course I could just make my own query but maybe I'm forgetting an option to insert this data using a existing function. $userdata = array( //user login 'user_pass' => esc_attr( $_POST['pass'] ), 'user_login' => esc_attr( $_POST['user'] ), 'user_email' => esc_attr( $_POST['email'] ), //user meta 'rich_editing' => false, 'comment_shortcuts' => false, 'show_admin_bar_front' => false, 'wp_user_level' => 0, 'wp_capabilities' => 'a:1:{s:10:"subscriber";s:1:"1";}' ); $new_user_user_id = wp_insert_user( $userdata );
What you are best off doing is hooking into `user_register` and from there updating the user options you want them set to. Below is an example of disabling the admin bar for new users: add_action("user_register", "sc_set_user_admin_bar_false_by_default", 10, 1); function sc_set_user_admin_bar_false_by_default($user_id) { update_user_meta( $user_id, 'show_admin_bar_front', 'false' ); update_user_meta( $user_id, 'show_admin_bar_admin', 'false' ); }
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "user registration" }
Help with Changing loop.php? I'm trying to edit the loop so if its on category ID 60 it displays "Photos" instead of "Blog".. how do I do this? blog <?php if(is_archive()&&!is_category()&&!is_tag()&&!is_search()){ ?> <!-- BEGIN .archive-title --> <h1 class="page-title"> <?php if ( is_day() ) : ?> <?php printf( __( 'Daily Archives: %s'), get_the_date()); ?> <?php elseif ( is_month() ) : ?> <?php printf( __( 'Monthly Archives: %s'), get_the_date( 'F Y' )); ?> <?php elseif ( is_year() ) : ?> <?php printf( __( 'Yearly Archives: %s'), get_the_date( 'Y' )); ?> <?php else : ?> <?php _e( 'Blog Archives'); ?> <?php endif; ?> <!-- END .archive-title --> </h1> <?php } ?>
<?php if( is_archive() && is_category() && !is_tag() && !is_search() ): ?> <!-- BEGIN .archive-title --> <h1 class="page-title"> <?php if ( is_day() ): ?> <?php printf( __( 'Daily Archives: %s' ), get_the_date() ); ?> <?php elseif ( is_month() ): ?> <?php printf( __( 'Monthly Archives: %s' ), get_the_date( 'F Y' ) ); ?> <?php elseif ( is_year() ): ?> <?php printf( __( 'Yearly Archives: %s' ), get_the_date( 'Y' ) ); ?> <?php elseif ( is_category(60) ): ?> <?php _e( 'Photos' ); ?> <?php else : ?> <?php _e( 'Blog Archives' ); ?> <?php endif; ?> <!-- END .archive-title --> </h1> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "loop" }
Perform an action when post is updated/published I'd like to run a custom query using some meta data whenever a post is updated or published. Is there something I can put in functions.php to fire when those events occur?
The `save_post` action fires When a post is updated and/or published -- including when a new post is inserted. <?php add_action( 'save_post', 'wpse41912_save_post' ); function wpse41912_save_post() { // do stuff } If you want your functions to fire only when a post is being edited, you can hook into `edit_post`. If you want it to fire when a post is moved from draft to publish you can hook into `transition_post_status`.
stackexchange-wordpress
{ "answer_score": 11, "question_score": 6, "tags": "functions, actions" }
How to query posts that have certain post meta keys, and sort by meta key and/or value I'm using this structure to make album lists. I'm using a key so I correspond lists to albums but I don't know how to reverse the output so the items start at the top with lowest key value. Any ideas? <?php $album = get_post_meta($post->ID, "album", false); $album_list = get_post_meta($post->ID, "album_list", false); foreach ($album_list as $album_list) { list($key, $value) = explode(',',$album_list); $indexed_album_list[$key] = $value; } foreach ( $album as $each_album) { list($key,$album) = explode(',',$each_album); echo '<div>'.$album.'</div>'; echo '<div>'; if ($album_list = $indexed_album_list[$key]) { echo $album_list; } else { echo '&nbsp'; } echo '</div>'; } ?>
how about array_reverse() < there are a bunch of array manipulation functions at php.net. i'm always there looking something up. also sort() might be useful **EDIT** based on your comments: sort($album); print_r($album); should return: Array ( [0] => 001,Get Rich Or Die Tryin [1] => 002,Curtis [2] => 003,The Massacre [3] => 004,Before I Self Destruct )
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom field, lists" }
Disable qTranslate by post type in admin + disable per page / post ID on front-end I'm trying to find a way to selectively disable qTranslate - I would like to be able to show certain static content on my site in 4 languages, but to then only have a single language (and a simplified editor) for posts and also custom post types. I would also need to disable the output on selective pages in the front-end, so that I can show all the language content on the same page, at the same time. Is there a way to have the plugin load on demand?
Following snippet will disable it for post_type `post` (modify array below to affect other post_types): function qtrans_disable() { global $typenow, $pagenow; if (in_array($typenow, array('post')) && // post_types where qTranslate should be disabled in_array($pagenow, array('post-new.php', 'post.php'))) { remove_action('admin_head', 'qtrans_adminHeader'); remove_filter('admin_footer', 'qtrans_modifyExcerpt'); remove_filter('the_editor', 'qtrans_modifyRichEditor'); } } add_action('current_screen', 'qtrans_disable'); Similarly you can disable it for specific post IDs. However take into account that this **_won't affect_** already existing multi-languaged content. Therefore use it before you enter any.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "plugins, multi language, plugin qtranslate" }
Problem with comment box The "Reply" option on the comment box is not working. Please let me know how to make that work? Note: I am able to reply on comments from admin area (wp->comments->...) but the site visitors are not able to reply. For example check this: www.linuxstall.com/linux-command-line-tips-that-every-linux-user-should-know/ Click on "Reply" there. You will not be able to reply to that comment. You can add new comment though but "reply" will not work. Let me know how to solve this issue. Thanks.
Make sure your header.php file has this before the wp_head function: <?php wp_enqueue_script( 'comment-reply' ); ?> **Note:** Some themes may use the comment-reply function in the themes function.php file. ## Caution: I've scanned your theme and I notice it's using an outdated version of TimThumb which is a serious security flaw. You can install the TimThumb Vulnerability Scanner Plugin to do an auto-check, it also updates TimThumb to the latest version for you. You should fix this immediately. **UPDATE:** The question continued via email. The theme worked fine on my site which led me to believe it was a plug-in conflict. I suggested the **standard undershooting steps:** 1. Disable all plug-ins 2. Enable them one at a time to reveal the conflicting plug-in 3. Remove the plug-in and find one to take it's place or attempt to make changes to repair the issue.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "comments" }
Adding session variable and/or cookie based on user-selected input I am working on a classifieds website that has a custom taxonomy called 'countries'. In the main header menu I have these categories showing in a dropdown list of particular countries people can browse the site by. How would I basically make it so when someone selects their country, it sets a session variable and or cookie with their location and from there on, every part of the site that shows a listing will use this value in a custom WP_Query to only query posts of that particular country? So someone comes to the homepage, selects their country and then the page reloads with their chosen country for every page load thereafter.
You can definitly use PHP session variables. Follow this blog post ("Listing 3") for the best way to enable PHP sessions in WordPress. Namely, you need to use this code in your plugin or in your theme's funtions.php: add_action( 'init', 'session_start', 0 ); After that you can use basic session variables to set the country when the user selects it, and subsequently access the country that the user has selected. Good Luck!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom taxonomy, wp query, taxonomy, location search" }
Adding Sub Menu In a theme which Do not have Menu Options I am a new bee in wordpress but i can code in PHP. I have a free wordpress theme installed on my local host. The theme Do not have an option to add to add menu/sub menu in it. It comes with predefined number of menus. What i want is , can i add sub menu in the theme using some php skills? what i want is, a drop down sub menu when we hover over a menu.. Can i do it? if yes, How can i do it? i searched a lot, got videos and help about sub menus, but all of the help is about the themes which allow sub menu. **Clarification :-** i am not an expert, but what i know and what i think is that, it is a wordpress issue, i would need to code in menu.php or function.php to append sub menu to each element of main menu. The theme does not allow sub menu. I need sub menu be created in theme. i am using Wordpress Christmas theme 1.1 (free) by instantshift
See the answer here: Dropdown Like Twenty-Eleven Theme Question Be sure to use the updated code toward the bottom of my answer. It should be self explanatory, but if you have any issues let me know and I'll help you out. Be sure to back up your files before changing them in case you break it. **How to Add the Menu After The Code is in Place** Once the menu is installed you should notice that the custom menu's are now available in Appearance>Menu's. Just type a menu name in the box provided, add some pages and posts, then drag the sub-menu pages below and to the right of the parent menu item and release. Be sure to save the menu when you're finished.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus, theme options, sub menu" }
Distribute post content through several divs I would like to distribute the content in a post through several divs. Much like a word processor distributes content through pages. Any ideas?
You have two options. You can either use a jQuery plugin like columnizer (even if you don't do columns, you can repurpose this plugin to split it how you want), or you can do it with PHP. Here's a great article that should get your started.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "plugins, posts, content, design" }
Stop Attachment image names from taking top level permalink I don't know why but images uploaded to my site in posts are getting a top level permalink. So if I upload an image into a post called "Apple" then it gets an attachment page at mysite.com/apple and that is a big problem for me. How can add a path between my top level and image attachment page name?
Don't link to attachment pages anywhere on your site and it won't matter what permalink they have. Search engines only see what you make public. BTW another thing you can try is to upload only from within the post/page edit screen. That way attachments take up the parent post/page permalink. Sort of like example.com/post-name/attachment-name.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, attachments, permalinks" }
posts_per_page & pagination conflict I have a custom query to display my custom post type. `posts_per_page` set to '5'. In admin post per page set to '10' (settings => Reading => Blog pages show at most 10 posts) My template lists 5 posts per page. If I have 15 posts it must be shown in 3 pages, **but on third page I get 404 error.** So my pagination uses the admin settings (10 posts per page). How can I fix it? global $paged; query_posts(array( 'post_type' => 'custom_post_type', 'posts_per_page' => 5, 'orderby' => 'title', 'order' => 'ASC', 'paged' => $paged )); while (have_posts()) : the_post(); the_title(); endwhile; next_posts_link('Next'); previous_posts_link('Prev');
Pagination is calculated before you get to the template file that runs `query_posts`. The proper way to alter `posts_per_page` conditionally is to use the `pre_get_posts` hook to modify the main query.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "pagination, loop" }
Is there a ready-made fix to make the admin bar not obscure content? I have a situation where the Wordpress 3 Admin Bar (which is cool and I do want to have) obscures some important information on my page. Before I start fiddling with the CSS myself (which I'm sure will break stuff): Is there an existing patch to change this so the Admin Bar starts "above" the actual page? I realize there may be CSS complications (especially with absolutely positioned elements), but it should be possible.
Upon closer inspection, I found out that Wordpress already _does_ try to move everything that would be obscured further down. The problem is elements that have been positioned using `position: fixed` or `position: absolute`. What I ended up doing is adding separate CSS rules for those that apply only when the `admin-bar` class is set on the body (which Wordpress does automatically when the bar is visible.) like e.g. so: /* Normal mode */ ul.sidemenu { top: 4px; left: 4px; ..... etc. etc.} ul.langmenu { top: 4px; right: 4px; .... etc. etc. } /* Move elements 28px down when the admin bar is visible */ body.admin-bar ul.sidemenu { top: 32px} body.admin-bar ul.langmenu { top: 32px}
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "admin bar" }
Using str_replace on wp-admin I'm currently having some difficulties getting this below snippet to work. The current outcome is it replaces nothing. _I realize this particular question could also be solved using`gettext`, but I was looking a general example solving all of my `str_replace` questions at once._ add_filter( 'admin_print_scripts-index.php', 'wpse_replace_version_message' ); /** * wpse_replace_version_message */ function wpse_replace_version_message( $html ) { $html = str_replace( '<span id=\'wp-version-message\'>You are using <span class="b">WordPress 3.4-alpha-19904</span>', '', $html ); return $html; }
I haven't tested this code, but I think it will work for you. I just put `add_filter` after the function and chose `preg_replace`: <?php /** * wpse_replace_version_message */ function wpse_replace_version_message( $html ) { $html = preg_replace( '<span id=\'wp-version-message\'>You are using <span class="b">WordPress 3.4-alpha-19904</span>', '', $html ); return $html; } add_filter( 'admin_print_scripts-index.php', 'wpse_replace_version_message' ); ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "customization" }
Installing Facebook comment plug in without loosing all previous wordpress comments? I'm trying to install Facebook comments onto a word press blog, but I do not want to loose all the previous comments. I'm curious if anyone has any ideas how to do this. I've looked at a lot of the various plugins, and haven't been able to find a good solution. I would like to find a way for the Facebook comment system to be the default comment system, and if someone doesn't have Facebook (or doesn't want to use it) they can use the default wordpress comment system (unless something different exists.) Another option is to use the default wordpress plug in on all previous posts, and moving forward use just the Facebook plug in. I just don't want it to look like all previous posts have no comments when they actually do, if that makes sense. I'm open to any ideas that you have. Thanks!
From all I could research on this, there's just no way to "merge" existing WP comments onto the Facebook Plugin. So my solution for this problem with a client was to style wordpress comments exactly like fb comments, except that they always appear below all other fb comments. Then, by default, i leave the fb comment form loaded on the single page, and at the bottom of everything i have this "don't use facebook? comment here" button, calling WordPress' default popup comments window. This way you can still have both functionalities and still privilege fb comments. **EDIT:** I didn't realize you were talking about plugins in general, and not about the actual FB Comments App. My solution was to install it by hand, on the actual `comments.php` instead of looking for a plugin. It turned out to be easier than to find a plugin that would do it exactly as i wanted.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "plugins, comments, facebook" }
Resizing image into thumbnail, small, medium and large options greyed out I am working with WordPress 3.3.1 and cannot resize the image I am trying to add to the page as the thumbnail, small, medium and large options are greyed out. the size of the image in question is 276x354. I have created my own theme and have added `<?php the_post_thumbnail(); ?>` template tag but to no avail. Does deactivating the visual editor have anything to do with this. I have not come across this problem before and would appreciate any pointers on what could be causing this problem. Thanks in advance. nav
it can be caused by multiple reasons , some of which may be : * theme disabling this function => switch to default theme and check function again * GD library not installed on server => check your PHP server settings . * the image you are inserting is smaller than the thumbnail image size set in Admin/Settings/Media. => check your default image sizes and / or upload a bigger image * some plugin is causing it => disable all plugins and check function again. * Defected image => Try another image * Max file upload restriction => In functions.php @ini_set( 'upload_max_size' , '64M' ); @ini_set( 'post_max_size', '64M'); @ini_set( 'max_execution_time', '300' );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "images" }