question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I'm using WordPress as a directory site, where a user can submit a post, which becomes their ad/listing. The users are assigned a custom wordpress role. Posts need to need to be approved and published by the admin once, and then they can freely update their post as they see fit. It work's fine like this at the moment because I haven't given the custom role any publishing capabilities. However, I also need the ability for the user to take their post offline (draft perhaps) temporary whenever they want, and make it published again whenever they want. Currently, when they make their post a "draft", they need to submit it for a review to make it published again - this isn't ideal. Is there a way around this so they can change their post from <code> published </code> to <code> draft </code> , and then back again from <code> draft </code> to <code> published </code> , without needing it to be approved? Or maybe I give them publish capabilities to start off with, but there's a plugin that requires their first post to be approved? (they are only permitted 1 post anyway). What about a custom metabox with a checkbox that controls whether or not the post is published? Unfortunately I would have no idea where to begin with this kind if functionality. I am using WPALchemy for other metaboxes though.
Thanks to Chris's suggestion of assigning a capability on the fly I was able to get something working that might help someone else. There may be a better method, but this one works well for my situation. Because I'm working with a custom post type of <code> listing </code> I needed to assign the mapped capability <code> publish_listings </code> to the user, but only after they are approved. The best way I could think of doing this was to include an "admin only" metabox on the custom post screens that only admins could see. This was done with the help of <code> WPAlchemy </code> and it's <code> output_filter </code> . With a metabox that only an admin could now see, I added a simple checkbox. When checked, and the post is updated, it adds the <code> publish_listings </code> capability to the author of the current post. being a type of directory site, I'm only allowing 1 post per author in my case so this works quite well. If unchecked and updated, the capability is removed. So the use case would look like this: User submits post for approval Admin reviews post, ticks the checkbox, and publishes the post for the first time User is now free to update their post at will, including making it a draft and publishing it again. As I mentioned, I'm using WPAlchemy for the heavy lifting of metaboxes, so I was able to utilise <code> save_filter </code> to add the capability when the post is updated. <code> function save_admin_only( $meta, $post_id ) { global $post; //get the author ID of the post we're on $author_id = $post-&gt;post_author; $id = get_the_author_meta( 'ID' , $author_id ); $user = new WP_User( $id ); //retrieves the user, based on their ID specified above for user with WP_User class if($meta['_can_publish'] == 'yes') { $user-&gt;add_cap( 'publish_listings' ); //assign capability to this user if checkbox is ticked } else { $user-&gt;remove_cap( 'publish_listings' ); } //otherwise remove the capability so they can not publish return $meta; } </code> If you need to check for a custom post type (say you had more than one), you can wrap it with: <code> if ( 'other_post_type' == get_post_type() ) { ... } </code> This looks like it could be extremely helpful for other scenarios where you don't want to create a whole new role, just to give a user some capabilities. If anyone can improve on the above, then please do.
How to allow a user to make their post (ad) a draft, and then publish again without needing approval?
wordpress
I have a Wordpress site in which the background color is black and the text is white. The site is fine, but it's a pain trying to edit content in the visual editor as the background is white (same color as the text). I end up having to tell users to use the HTML view or write up the content in black color text and then at the end just select all the text and flip it to white (in which case many of them freak out and think their text is now deleted!) How do I change the background color of the editor to black (or any other color) so that the content can be readable if the text color is to be white?
similar to the answer by GavinR, using the wordpress <code> add_editor_style() </code> function; (as implemented in Twenty Ten and Twenty Eleven) in functions.php of your theme, add: <code> add_editor_style(); </code> then create an editor-style.css in your theme folder: <code> .mceContentBody.wp-editor { background-color: #000; color: #fff; } </code>
How do you change the visual editor's background color?
wordpress
How can I limit the amount of results returned? <code> $images = $wpdb-&gt;get_col(" SELECT ID FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND ID in ($meta) ORDER BY menu_order ASC "); </code>
<code> $images = $wpdb-&gt;get_col(" SELECT ID FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND ID in ($meta) ORDER BY menu_order ASC LIMIT 5 "); </code> Like @Kaiser suggested you can specify a range (5th to 20th results, a total of 15 results are returned at max) like this: <code> $images = $wpdb-&gt;get_col(" SELECT ID FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND ID in ($meta) ORDER BY menu_order ASC LIMIT 5,20 "); </code>
Limit amount of results returned
wordpress
Im using this code to prevent duplicate post from being added but i also need to prevent duplicate pages too. Can Someone please help? <code> function clearDuplicatePosts(){ global $wpdb; $prefix = $wpdb-&gt;prefix; $wpdb-&gt;query("DELETE bad_rows . * FROM ".$prefix."posts AS bad_rows INNER JOIN ( SELECT ".$prefix."posts.post_title, MIN( ".$prefix."posts.ID ) AS min_id FROM ".$prefix."posts GROUP BY post_title HAVING COUNT( * ) &gt;1 ) AS good_rows ON ( good_rows.post_title = bad_rows.post_title AND good_rows.min_id &lt;&gt; bad_rows.ID )"); } add_action('publish_post', 'clearDuplicatePosts'); </code>
you can use the same function simply hook it to the <code> publish_page </code> hook or any custom post type for that matter <code> publish_{post type name} </code> so just add : <code> add_action('publish_page', 'clearDuplicatePosts'); </code>
Prevent duplicate pages from being added
wordpress
How to check if jQuery library exist in head tags? <code> &lt;head&gt; &lt;script type="javascript/text" src="http://code.jquery.com/jquery-1.6.2.js"&gt;&lt;/script&gt; &lt;/head&gt; </code> and if not exist how do I load in head tags the jquery library, I'm doing a plugins and I want to load my plugins script in jQuery and also do able to check if jQuery library exist so my jQuery script will run
scripts and styles should never be embedded directly in themes or templates because of potential conflicts between plugins and themes. To use jQuery in a plugin or theme it should be enqueued with wp enqueue script . This will make sure it's added only once, and any scripts that define it as a dependency will load after.
Check if jquery library exist
wordpress
I have change the main URL of my wordpress theme. I accessed <code> Admin area =&gt; Settings =&gt; and change my URL from : www.sampleURL.com to www.sampleURL.com/?page_id=2 </code> and now every time I enter <code> www.sampleURL.com/wp-admin </code> i get directed to <code> www.sampleURL.com/?page_id=2 </code> Please help!
Not sure why you would want to make that change, but if worst comes to worst, you can change it back via the database. Assuming you can access your MySQL database directly, simple navigate to the wp_options table and change the value of <code> siteurl </code> and/or <code> home </code> to your desired values. EDIT: Alternatively, if you can access your code, in the theme's functions.php file, add the following code. <code> update_option( 'siteurl', 'http://sampleURL.com' ); update_option( 'home', 'http://sampleURL.com' ); </code> Obviously, swap http://sampleURL.com with your URL. Then refresh the home page of your site a couple times. Once everything is back to normal, remove this code.
I can't access my admin page after changing main url
wordpress
I have a site visibility in privacy settings set to allow search engines to see my site but for some reason when i go to the auto generated robots.txt file it shows User-agent: * Disallow: switching site visibility merely adds/removes a trailing slash ie "Disallow: /" i have 2 related plugins "all in one seo tools" and "google xml sitemaps" but i disabled both of these to no avail any ideas anyone .... i know how to override this with a manual sitemap but i'm trying to find out whether this is WordPress intended behavior and if so why
Disallow with no trailing slash is the same as "allow all" - see here - nice find!
auto generated robots.txt problem
wordpress
We have a large wp install that is freezing up whenever an editor hits "publish". It seems that the culprit is the pinging processes that run, such as re-building the sitemap, etc. Is it possible to move most of these processes to the background so that the site doesn't hold up until the processes are complete?
Pinging and similar is all done in the background already. If you have a plugin rebuilding a sitemap or something, then consider using a different plugin which doesn't have the same rebuilding time issue.
How to move post process to background
wordpress
Given a wordpress multisite network, with a main blog, and assuming all content has been moved on to that blog, how would one collapse the network back down into a standard wordpress non-network non-multisite install?
I've gone through the steps to extract a site from a multisite install to a single instance now: Set up a clean copy of WP but don't install it Find the site ID Copy the files from blogs.dir/ID/files to the new WP uploads folder Copy the theme the site uses and any plugins it uses to the appropriate folders in the new wp-content folder Take a back up of the multisite database but only the tables for the target site and the users and usermeta tables using MySQL workbench or equivalent Restore the backup to a new database and change the table name prefixes so they are all the same eg. 'wp_SITEID_' to 'wp_' Using MySQL workbench or query browser tidy up the users and usermeta tables like so: <code> DELETE FROM wp_usermeta WHERE user_id NOT IN( SELECT distinct(user_id) FROM wp_usermeta where meta_key LIKE 'wp_SITEID_%' ); </code> <code> DELETE FROM wp_users WHERE ID NOT IN( SELECT distinct(user_id) FROM wp_usermeta where meta_key LIKE 'wp_SITEID_%' ); </code> <code> UPDATE wp_usermeta SET meta_key = REPLACE( meta_key, 'wp_SITEID_', 'wp_' ) WHERE meta_key LIKE 'wp_SITEID_%'; </code> <code> UPDATE wp_options SET option_name = REPLACE( option_name, 'wp_SITEID_', 'wp_' ) WHERE option_name LIKE 'wp_SITEID_%'; </code> Begin the WP install process to create a <code> wp-config.php </code> but don't click 'Run the install' Create a default .htaccess file if permalinks were in use or just visit the permalinks page in wp-admin You'll need to update any old URLs in your database next. Ideally use a safe search/replace tool like the one in wp-cli or its general purpose precursor search/replace db by interconnect/it . Specifically replace <code> blogs.dir/SITE_ID/files </code> with <code> uploads </code> , and if you're changing your site URL search for <code> oldsite.com </code> and replace with <code> newsite.com </code> . A fair bit of effort and you have to be careful with the database edits but that's the only I can see to extract a single site from an existing multisite with all its settings etc... intact. EDIT: As spotted by @Jake I forgot to mention the final steps you may need to take eg. search/replace of old URLs. I've updated the list accordingly.
Convert a Multisite Wordpress install into a Single site
wordpress
I was making minor changes to <code> functions.php </code> file but just as I made the changes I got an error, I used <code> FileZilla </code> and undo the function I added but now I am getting the following error, Fatal error: Call to undefined function add_action() in /home/content/93/7877293/html/wordpress/wp-includes/functions.php on line 51 I am sure that the file is now in its original condition. Can anyone help me by suggesting me how to deal with it? Thanks in advance.
You're not supposed to edit <code> wp-includes/functions.php </code> but <code> wp-content/themes/your-theme/functions.php </code> .
Error after editing functions.php
wordpress
example page; http://www.c-art.org.uk/2011/07/01/jenny-abbot/ some reason the gravatar image is overwriting the posts featured image thumb (100x100). Nnot sure how its doing it! How can i get rid of it? <code> &lt;meta property="og:title" content="Jenny Abbot" /&gt; &lt;meta property="og:description" content="C-Art — Cumbria Artist Open Studios, Jenny Abbot Artist Index PaintingC-Art"/&gt; &lt;meta property="og:url" content="http://c-art.modernactivity.co.uk/?p=1254"/&gt; &lt;meta property="og:image" content="http://www.c-art.org.uk/wp-content/uploads/Summer-at-Sea-Wood-100mm-100x100.jpg"/&gt; &lt;meta property="og:type" content="article"/&gt; &lt;meta property="og:site_name" content="C-Art"/&gt; </code> best, dc.
I can't see a Facebook share button on the page you are talking about , but I ran this through Facebook Lint and it appears that your Open Graph meta tags are working correctly.
open graph image being overwritten by gravatar logo?
wordpress
Uploading an image to add to a page, I got a message saying: Unable to create directory... Is its parent directory writable by the server? Assuming the issue is that the parent directory needs to be made writable by the server, how do I make the parent directory writable by the server? Thanks, Richard
Here is how to change your folder permissions. Login to your ftp Make your wp-content folder 755 (In most FTP programs, this involves right-clicking -> "Permissions"). 755 is owner: read, write and execute permissions; group: read and execute permissions; others: read and execute permissions. Inside wp-content create a new folder called "uploads", make it 755 (if not working, try 777 for testing, but never make a live site 777) Inside the control admin panel, go to settings> miscellaneous and on the first line enter "wp-content/uploads" as where your uploads will go to. If this does not work you will have to log in to your server via SSH and make sure the ownership of the web folders are set to the webserver user (using the chown command)
Making a parent directory writable by the server
wordpress
How can I list all pages within a certain parent (ID=917) and show the month and year they were published in this format: Aug 2011 This is a page (link to page) This is another page (link) Jul 2011 Jun 2011 This is another page (link) etc etc UPDATE: Also, just in case, how can I just show the months that have a page within it? So from the example above, it wouldn't show Jul. Please don't tell me to use posts instead of pages as that isn't an option on the setup I have.
Ok firstly, create a php file inside your theme's folder and give it a name that won't clash with any of the native theme template files, archive.php, index.php etc... (give it a unique name, something like page-list-by-month.php ). Add the following code to that file. <code> &lt;?php /** * Template Name: Pages by Month */ get_header(); ?&gt; &lt;!-- Your opening outer HTML --&gt; &lt;?php $args = array( 'post_type' =&gt; 'page', 'orderby' =&gt; 'date', 'order' =&gt; 'asc', 'nopaging' =&gt; 1, 'post_parent' =&gt; 146 // &lt;--- Adjust this to the appropriate parent ); $data = array(); query_posts( $args ); if( have_posts() ) : while( have_posts() ) : the_post(); $date = explode( '%', get_the_date( 'Y%m' ) ); $year = $date[0]; $month = $date[1]; $data[$year][$month][] = get_the_ID(); endwhile; endif; // testing // print '&lt;pre&gt;';print_r( $data );print '&lt;/pre&gt;'; foreach( $data as $year =&gt; $months ) { foreach( $months as $month =&gt; $page_ids ) { echo date( 'F', mktime( 0, 0, 0, $month ) ) . ' 2011&lt;br /&gt;'; foreach( $page_ids as $page_id ) echo '&lt;a href="' . apply_filters( 'the_permalink', get_permalink( $page_id ) ) . '"&gt;' . apply_filters( 'the_title', get_the_title( $page_id ) ) . '&lt;/a&gt;&lt;br /&gt;'; } } ?&gt; &lt;!-- Your closing outer HTML --&gt; &lt;?php //get_sidebar(); ?&gt; &lt;?php get_footer(); ?&gt; </code> Save the file. Now create a page and select the Pages by Month template in the Page Attributes metabox, what you enter for the content and title doesn't matter, though the title you give this page will determine the URL, so consider where you want this special page to appear and use a title appropriate for that. Example title -> My Page Archive = http://example.com/my-page-archive Once the page is created and the template has been attached, that's it.. NOTE: Be sure to adjust the <code> post_parent </code> value in the args array and additionally be sure to add appropriate HTML where indicated(the markup will differ depending on theme so i left it out the sample). Hope that helps.. :) (oh and Mark would be me - when i'm not at my regular PC)..
List pages within a certain parent and show published month
wordpress
In theme Twenty Eleven, do the default images rotate randomly, or with some sequence? As far as I can see, I think it's random, but there might be some pattern/sequence that I didn't notice.
the header image is picked at random; see this line in /wp-includes/theme.php line 1476: <code> $random_image = array_rand( $headers ); </code> out of interest: why are you asking, and what difference would it make?
In theme Twenty Eleven, do the default images rotate randomly?
wordpress
I'm facing a design, that has two titles. I have no clue how can I two titles in wordpress. In a nutshell: Creating a page, there you can set the title. How can I have two titles there? Or similar effect?
Strictly speaking title is column in posts database table so it is not easy (or makes sense) to add one more title. But it is trivial to emulate by using custom field to store additional title (or anything else).
How can I have two content titles?
wordpress
The Puzzle: I am currently working on a music blog that has various venues and numerous locations that are laid out at the top of each post as follows: USA.California.Los Angeles. Hollywood Bowl Note: Everything except the venue name (Hollywood Bowl) is bold. In order to limit the number of calls to the server I have clumped all the title information into a single array (as seen below). As of now I am simply calling everything in the array consecutively: <code> &lt;?php $custom_fields = get_post_custom($post-&gt;ID); for ($i = 1; $i &lt;= 4; $i++) { if(isset($custom_fields["rw_location_$i"])){ ?&gt; &lt;h1&gt;&lt;?php echo get_post_meta ($post-&gt;ID,"rw_location_$i", true ); ?&gt;&lt;/h1&gt; &lt;?php } ?&gt; &lt;?php } ?&gt; </code> The Question: How do I still make a "single call" but create a unique class (h1,h2,h3) for different <code> $i </code> ? For example have the <code> $i = 1 </code> be a <code> &lt;h1&gt;&lt;/h1&gt; </code> tag and <code> $i = 2,3,4 </code> be <code> &lt;h2&gt;&lt;/h2&gt; </code> tags. I hope my question is clear enough, if not I'd be happy to elaborate further. (P.S. I know the numbering is off, but I'm sure we can all overlook that)
To are still call database inside the by <code> get_post_meta() </code> where you already have the values in <code> $custom_fields </code> variable. Try something like this: <code> &lt;?php $custom_fields = get_post_custom($post-&gt;ID); for ($i = 1; $i &lt;= 4; $i++) { if(isset($custom_fields["rw_location_$i"][0])){ if($i==1){ echo '&lt;h1&gt;';} else {echo '&lt;h2&gt;';} echo $custom_fields["rw_location_$i"][0] if($i==1) {echo '&lt;/h1&gt;'; }else {echo '&lt;/h2&gt;'}; } } ?&gt; </code> If I get your question right. Are you looking to echo <code> &lt;h1&gt; </code> for the first iteration and <code> &lt;h2&gt; </code> for all other iteration?
PHP Puzzle: Unique Styles with PHP loop
wordpress
Setting up WordPress, I'm getting the following message: "Sorry, but I can't write the wp-config.php file. "You can create the wp-config.php manually and paste the following text into it." Do I copy-paste the text into a file and upload that to the server? If yes to question 1, to create the file, is Text Wrangler an appropriate program to use? (I use a Mac) If Text Wrangler is an appropriate program, in saving the file, would I choose "Line breaks: Unix (LF)" and "Encoding: Unicode (UTF-8)" and would I manually add ".php" to the file name when I save it? The text that WordPress is giving me to paste into wp-config.php includes comments such as: * * This file is used by the wp-config.php creation script during the * installation. You don't have to use the web site, you can just copy this file * to "wp-config.php" and fill in the values." and: /**#@+ * Authentication Unique Keys and Salts. * * Change these to different unique phrases! * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1 > /salt/ WordPress.org secret-key service} * You can change these at any point in time to invalidate all existing cookies. This > will force all users to have to log in again. ...do I just copy all this into the file wp-config.php and upload it to the server? Thanks, Richard
Here is how you make your config.php manually: In your download there should be a wp-config-sample.php. Open this is a text editor. Fill in your database connection details. Go to https://api.wordpress.org/secret-key/1.1/salt/ and get the code. Copy the above cope and paste into the sample file over the top of the existing <code> defines </code> Save the file as wp-config.php The answer to "should I put it in public_html?" is yes if thats where the rest of your wordpress files are.
Creating the wp-config.php file manually
wordpress
With the current version of wordpress 3.2.1 I am having this kinds of problem. I install wordpress frequently and I did not notice it before 3.2.1 Problem: Not being able to save settings under settings tab. The file names are <code> options-general.php </code> , <code> options-writing.php </code> , <code> options-reading.php </code> , <code> options-discussion .php </code> , <code> options-privacy.php </code> . Only settings that seems to be working is <code> options-permalink.php </code> . When I press the save settings button its just keep going and after couple of minutes its says "connection was reset" and some time with a "500 internal server error". However <code> options.php </code> page is also okey infact i am currently using it to same those information. Observations: Hosting: Tested in different hosting "inmotion", "hostgator" "godaddy". Technical info: All of those wordpress runs on Linux and apache. Browser: I know its not a browser issue but still i tested it with different browsers Firefox and Chrome. Theme installed: Some of those sites are using default 2011 theme and some custom theme. So, I don't think its a problem with theme. Plugins: Tested with fresh wordpress install with no plugin/with plugin. UPDATE: Just downloaded the wordpress 3.2.1 zip file from wordpress.org and installed it to my localhost. Its seems fine in my local computer. But still having problem with wordpress in server.
On my observations. This is happening for only low speed users. When I tried from broadband the problem i seems to get away.
Problem saving wordpress settings with current version. Is it a bug?
wordpress
I've created a twentyeleven-child theme and activated it. I'm trying to increase the size of the body font on all pages. Do I do this in style.css of the twentyeleven-child theme? I can't find the right font in this file to change. In attempt to find it, I've searched all 10px, 11px, 12px, 13px, 14px, 15px, and 16px and changed them all to 20px, but the font size of the body text on my site is not increasing. I know that changes that I'm making to style.css are working, because other things are changing (for example, the menu font size).
The body font size in TwentyEleven is listed on line 316 in style.css <code> body, input, textarea { color: #373737; font: 15px "Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: 300; line-height: 1.625; } </code> Copy it over to your child theme style sheet and change the 15px to 20px. If you have already done this and it's not working make sure your child theme style.css has the correct headers: <code> /* Theme Name: Twenty Eleven Child Description: Child theme for the Twenty Eleven theme Author: Your name here Template: twentyeleven */ @import url("../twentyeleven/style.css"); /* Add your over ride rules below this line */ </code> If you need to debug your stylesheet and see which rules are being used by the browser you can use the webkit inspector included with Chrome or the Firebug Firefox plugin . To use the Chrome inspector highlight a section to inspect then right click and choose inspect element. You can also make on the fly css changes to see what they will look like. (Changes won't be saved when the page is refreshed). See Screenshot Below:
Modify Twentyeleven child theme CSS - How to change body font size?
wordpress
Is it possible to change the Home page so it's not a blog, but a page? And also is it possible to change the name of the homepage? If yes, how is this done? Thanks, Richard
To change the site Front Page to be a static Page : Go to <code> Dashboard -&gt; Settings -&gt; Reading </code> Change Front page displays from Your latest posts to A static page In the dropdown beneath this option, select the static Page to use as your Front Page. If you want to display your blog Posts somewhere, select a static Page to use to display them. To change the title of your Front Page: The Front Page will assume the Page Title of whatever static Page you selected above.
Changing the homepage
wordpress
Is there a way to set a url for a page, as per the following example: I want to change this url: http://richardclunan.com/?page_id=2 To: http://richardclunan.com/copy-critiques Is this possible? (I clicked Permalink Settings and specified 'copy-critiques' as Category Base, but this didn't do the trick...) Thanks, Richard
you can set the permalinks to <code> %postname% </code> , however this would change the permalinks for the whole site; and you can set the individual page permalink, which is normally derived from the page title, when you edit the page. btw: pages don't have a category base.
Setting a url for a page
wordpress
How can I change the ordering of menu items -- for example to make 'Wordfruit Copywriters' appear before 'How can you sell more of your product?' here: http://richardclunan.com/ Thanks, Richard
Go to appearance -> menus section. Here you can create menus, add menu items and drag them around to place it to your desired place. Alternatively, you can set up the menu order of a page. Just click edit page and you will see the menu order it should be under Page attribute section.
How to change order of menu items
wordpress
Do different themes accommodate different features, or can all themes accommodate any feature? I.e. do I need to bear in mind what features I'll need when I choose a theme, or are themes only how things are laid out visually? Also, is it possible to change the image in the default theme 'Twenty Eleven'? Thanks, Richard
No, not all Themes accommodate all features; but to answer that question more precisely, you'll need to be more specific about what you consider to be "features". Things that are generally considered Theme features are fairly well-represented by the list of filter tags for WORG repository-hosted Themes . You'll notice that these things generally deal with presentation of content. Things dealing with creation or management of content are generally considered Plugin territory, and generally speaking, any Theme should accommodate such Plugins. (Your second question is unrelated, and should be asked in a separate question.)
Do all themes accommodate all features?
wordpress
This website: http://www.ericpaulsnowden.com (The website is done in Wordpress). Loads pages and posts dynamically with AJAX/jQuery. Does anybody know how to do this?
I do, it's my site :) Here it is at a high level 1) I built the site as a standard html/css/javascript site without ajax and without Wordpress code. Layout complete without content. All links are regular a href links - this helps with backwards compatibility later. 2) Added in the Wordpress code to pull in content without ajax. Make sure all content is wrapped in a consistent div, which I call container. 3) I use jQuery to hijack all clicks on a href links. If there isn't target="_blank" or a class of override I then load the page using ajax. I grab the url, look for the div of container (defined above) and load just that content keeping the header and footer consistent. I also use JQuery address to change the url and title of the page. 4) When the content is finished loading I fire jQuery calls to fade in the content and reposition the bar under the nav. I also make additional calls to add any page specific JS back in as it gets stripped out by loading the page via ajax. 5) Finally I modified my .htaccess file to add a www. to every page and added javascript into the header of my file to add the hash into the url more jQuery address code to load the proper page if someone deep links. Hope some of this helps! Eric
How to load whole Wordpress pages dynamically with AJAX/jQuery like this following website?
wordpress
I have a non-Wordpress site , www.example.com For canonicalization purposes I have this in .htaccess : <code> Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.example\.com$ RewriteRule (.*) http://www.example.com/$1 [R=301,L] </code> This way all non-www links will be redirected to www version of site. Recently I decided to attach a wordpress blog at www.example.com/blog . After the installation is complete, whenever I go to www.example.com/blog I get 404 - Page not found error. I tried both auto install with Fantastico and a manual install, with the same result. I found out that when I remove the piece of code above from my .htaccess it fixes the problem, and wordpress installation is accessable and usable. However, I would like to keep the the original htaccess settings, for SEO purposes. I tried to change url version in wordpress General Settings and then restore main site htaccess file - it would still break the wordpress and 404 is back again. I tried to add next code in wp-config.php : <code> define('WP_HOME','http://www.example.com/blog'); define('WP_SITEURL','http://www.example.com/blog'); </code> It didn't fixed the problem either... I understand it has something to do with htaccess. I also notices that there is no htaccess file in wordpress folder, probably due to the fact that I haven't changed permalinks settings yet. I would appreciate any help on this matter! P.S: I just noticed that www.example.com/blog/wp-login.php is visible regardless of htaccess config, however after I log in it brings me to 404 page again :(
As per @Milo, I'm adding my comment above as an answer... Try going to <code> example.com/blog/wp-admin/options-permalink.php </code> . That should work, because the php file actually exists. If so, try updating your permalink options to a friendly version, like "Day and name". This will put a new <code> .htaccess </code> in the blog directory -- I'm thinking that that new <code> .htaccess </code> will override the one in the parent directory.
New installation can't be found due to htaccess of the original non-Wordpress site
wordpress
I want to add a list of my social media pages. What ways are there to do this? Are there widgets designed for this?
There are a couple of ways to do this. You can do as Chris Carson suggested and manually add them as a text menu. You can also make a text widget and use icons with links to the various services. If you're looking for something a little more robust, there's also a couple plugins and related services, such as AddThis, that do the icon and linking work for you and also let you track hit counts and such if you sign up for their free services.
Adding a list of social media links
wordpress
We created a theme that has a lot of changes in it. Now we want to enable that theme on our site in different colors, and a few images different: What we're doing is duplicating the theme, and then making a few changes in the CSS, and change a few images. But it seems an overkill - to copy the all the theme files just to make so few changes. Moreover, if we ever have to change something functional in the theme, we'll have to go through all the duplications and apply it. Is there a way to give users the option of changing colors &amp; images, without duplicating the theme?
We ended up using child themes, mainly because the site manager wanted to get a preview of the color change that would occur when changing CSS, and that was done best by the theme switching page , but also because it was easier...
Theme change only in CSS and a few images
wordpress
Is it possible to change the image in the default theme 'Twenty Eleven'? If yes, how is this done?
Just replace the default header image, under images/headers/path.jpg in your theme folder.
Is it possible to change the image in the default theme 'Twenty Eleven'?
wordpress
how can achieve this functionality. That I can change the themes "slogan" from admin and I don't have to go edit the themes source files. I think that there is some theme options functionality. But how to use it and maybe somebody can point me to the correct path. Added screenshot to clarify what I mean under slogan:
In wordpress that's a tagline.. maybe a plugin like this http://wordpress.org/extend/plugins/advanced-tagline/ can help you.
How to dynamically change theme's slogan from admin?
wordpress
if i follow the tutorials on how to add tinyMCE buttons for shortcodes ( for instance: http://www.garyc40.com/2010/03/how-to-make-shortcodes-user-friendly/ ) if i create a button that launches a form in a thickbox there is always this bit of code to create the launched form: <code> // executes this when the DOM is ready jQuery(function(){ // creates a form to be displayed everytime the button is clicked // you should achieve this using AJAX instead of direct html code like this var form = jQuery('&lt;div id="kiaAWeber-form"&gt;&lt;table id="mygallery-table" class="form-table"&gt;\ &lt;tr&gt;\ &lt;th&gt;&lt;label for="mygallery-columns"&gt;Columns&lt;/label&gt;&lt;/th&gt;\ &lt;td&gt;&lt;input type="text" id="mygallery-columns" name="columns" value="3" /&gt;&lt;br /&gt;\ &lt;small&gt;specify the number of columns.&lt;/small&gt;&lt;/td&gt;\ &lt;/tr&gt;\ &lt;/table&gt;\ &lt;p class="submit"&gt;\ &lt;input type="button" id="mygallery-submit" class="button-primary" value="Insert Gallery" name="submit" /&gt;\ &lt;/p&gt;\ &lt;/div&gt;'); var table = form.find('table'); form.appendTo('body').hide(); </code> but i am curious about this part in particular : // you should achieve this using AJAX instead of direct html code like this i've seen this on other tutorials, and in other plugins.... but all i've seen continue to do it this hard-coded way. does anyone have any insight into how to do this via ajax? i'd like to popular a select drop-down with values from get_options().. which i cannot do in jquery/java and the js file can't process the php either, so i figured ajax is the solution i'm just not sure how to start
by using jQuery.ajax() : so, instead of that big form variable: <code> $.ajax({ type: 'GET', url: 'admin-ajax.php', data: { action: 'get_my_form' }, success: function(response){ var table = $(response).find('table'); // you don't seem to use this "table" var $(response).appendTo('body').hide(); // ... } }); </code> Now, the php: <code> add_action('wp_ajax_get_my_form', 'get_my_form'); function get_my_form(){ // build your form here and echo it to the screen exit; } </code>
TinyMCE buttons that launch Ajax-generated forms
wordpress
Basically I want to rewrite: /edit/test-post to an existing page with a parameter: /edit?e=test-post From the examples in the Codex I created: <code> add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' ); add_filter( 'query_vars','my_insert_query_vars' ); add_action( 'wp_loaded','my_flush_rules' ); // flush_rules() if our rules are not yet included function my_flush_rules(){ $rules = get_option( 'rewrite_rules' ); if ( ! isset( $rules['(edit)/(\d*)$'] ) ) { global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); } } // Adding a new rule function my_insert_rewrite_rules( $rules ) { $newrules = array(); $newrules['(edit)/(\d*)$'] = 'edit?&amp;e=$matches[2]'; return $newrules + $rules; } // Adding the id var so that WP recognizes it function my_insert_query_vars( $vars ) { array_push($vars, 'e'); return $vars; } </code> However, I simply cannot get it working, what am I doing wrong? Thanks!
By 'existing page' do you mean a WordPress page? My experience with rewrites is routing everything to index.php with whatever extra query vars you need, I think attempting to route it to <code> edit </code> is one of your issues, not entirely clear on your intent there. Go download Monkeyman Rewrite Analyzer if you don't already have it, it's a great tool for testing these things out. I tested out the following rule to verify it works. All requests to <code> /edit/* </code> load a page named 'edit', <code> get_query_var('e') </code> returns the correct value for <code> e </code> in my template. Note I didn't flush the rules here, I usually just visit the <code> Settings &gt; Permalinks </code> page and click save to flush whenever I change them. <code> &lt;?php add_action( 'init', 'my_rewrites_init' ); function my_rewrites_init(){ add_rewrite_rule( 'edit/([^/]+)/?', 'index.php?pagename=edit&amp;e=$matches[1]', 'top' ); } add_filter( 'query_vars', 'my_query_vars' ); function my_query_vars( $query_vars ){ $query_vars[] = 'e'; return $query_vars; } </code>
Can't get rewrite rules working
wordpress
I've downloaded WordPress and I want to ensure I'm uploading it to my server correctly: I see there's a .zip file and a .tar.gz file -- which should I use? It's an Apache server. This is the place my site will be: http://plowtoplate.com/ I want the site to be at http not at www., but I do want either the site to also be visible at www. or for the www. to redirect to http -- where should I upload the WordPress files? Into public_html? or just into the place I get to when I login with ftp? (the 'root' I think that's called...?) Do I unzip wordpress-3.2.1.zip and upload those files, or do I upload the .zip to the server? Once the files are uploaded, is there anything else to do before it's ready to go? How do I get the username and password to login to the admin panel so I can build the site? And what url do I go to to login? Beginner questions, I know. I appreciate help. Thanks, Richard
WordPress Codex has quite extensive installation instructions . I see there's a .zip file and a .tar.gz file -- which should I use? No difference. Archive format is merely for convenience, contents are the same. I want the site to be at http not at www., but I do want either the site to also be visible at www. or for the www. to redirect to http -- where should I upload the WordPress files? Into public_html? It depends on how your domain is set up, but usually both www and non-www version point to same thing. <code> public_html </code> is probably right directory. You will only be able to pick www or non-www link when configuring WordPress. Redirecting other version will need a bit of <code> .htaccess </code> tweak, google it. Do I unzip wordpress-3.2.1.zip and upload those files, or do I upload the .zip to the server? Depends on how comfortable you are with server-side manipulation. Uploading unpacked files is easier, uploading archive and unpacking on server (using SSH or cpanel for example) is faster. Note that there is <code> wordpress </code> directory in archive which you don't need, files whould be unpacked to the root of the site. Once the files are uploaded, is there anything else to do before it's ready to go? See link to Codex above, you should have database created, etc. How do I get the username and password to login to the admin panel so I can build the site? And what url do I go to to login? Trying to visit site with freshly uploaded WordPress files will redirect you to <code> install.php </code> that will guide you through initial configuration. Initial setup should have link to admin area in theme sidebar, you can also always go there by visiting <code> /wp-admin/ </code> URL.
Basic installation questions
wordpress
I want to specify for the images of my post - if is number x, output this, else if is number y output this instead, etc. I'm trying make specific treatments to my 1st, 4th, 9th images for that post. This code below is the code i'm using to just simply output all of my images for the post. Any ideas? <code> &lt;?php $images = get_post_meta($post-&gt;ID, 'rw_postpage_images'); ?&gt; &lt;?php foreach ($images as $att) { $src = wp_get_attachment_image_src($att, 'full'); $src = $src[0]; $image_path = thumbGen($src,80,80,"crop=1&amp;halign=center&amp;valign=center&amp;return=1"); ?&gt; &lt;div class="post_item"&gt; &lt;div class="small"&gt; &lt;img src="&lt;?php echo $image_path; ?&gt;" alt="&lt;?php the_title(); ?&gt;" title="&lt;?php the_title(); ?&gt;" width="80" height="80"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; </code>
set a counter variable outside the foreach, check its value in each iteration and output corresponding markup, then increment it at the end for the next iteration. <code> &lt;?php $images = get_post_meta($post-&gt;ID, 'rw_postpage_images'); // set a counter $image_counter = 1; foreach ($images as $att) : $src = wp_get_attachment_image_src($att, 'full'); $src = $src[0]; $image_path = thumbGen($src,80,80,"crop=1&amp;halign=center&amp;valign=center&amp;return=1"); // check the counter if( $imagecounter == 1 ) : // output markup for first image elseif( $imagecounter == 4 ): // output markup for fourth image elseif( $imagecounter == 9 ): // output markup for ninth image else : // markup for all the others ?&gt; &lt;div class="post_item"&gt; &lt;div class="small"&gt; &lt;img src="&lt;?php echo $image_path; ?&gt;" alt="&lt;?php the_title(); ?&gt;" title="&lt;?php the_title(); ?&gt;" width="80" height="80"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endif; // increment the counter $imagecounter++; endforeach; ?&gt; </code> I put comments in there where markup would go to keep things shorter. just put whatever markup you want output there for that particular position similar to the last <code> else: </code> block.
Specify what to do for a specific image number of the post
wordpress
When doing a bit of Google searching for content on our blog, I noticed to my shock and horror that individual images from the Media Library are somehow generating their own URLs that Google is somehow finding and indexing! For example this page: stackexchange-url ("http://blog.stackoverflow.com/2008/08/special-development-team-podcast/") Contains this image: stackexchange-url ("http://blog.stackoverflow.com/wp-content/uploads/bio-jarrod-dixon.jpg") Which is fine, but somehow this image is also exposed as its own URL and "post": stackexchange-url ("http://blog.stackoverflow.com/2008/08/special-development-team-podcast/bio-jarrod-dixon/") This is extremely unwanted! I checked the Media settings in WordPress and browsed around the Media Library but I can't figure out a way to disable this behavior. Any ideas?
This thing you are saying is unwanted is just normal functionality under WordPress and it cannot be removed. However there are things you can do to point the unwanted URL to something more usefull. Here is a forum post on this issue with some interesting fixes and a description on what is happening: http://wordpress.org/support/topic/disable-attachment-posts-without-remove-the-medias Attachments are actually a post type, so they take a row in the posts table like a post does, they will always have a URL available, in the same way that posts do to.. ie. <code> example.com/?p=16 </code> 16 is the post ID, and like posts they will always be available by a URL like the above. Media files aren't simply considered files, they have a more content like element to them, in that they have a record in the posts table that corresponds to them, just like a post or page does. What you're asking is how to stop the automatic existance of individual attachment URLs for each media item(not really possible because they're essentially a post type, which means they'll always be a URL for them). Here's a suggestion though, take any template(theme) file, index.php, page.php, archive.php or whatever you like, create a copy and rename it to image.php or attachment.php if you want to target all media. Open the file, remove the loop, save... and load up one of the attachment pages(like the one you provided before).. My point being, all you need to do is create an attachment template file: http://codex.wordpress.org/Template_Hierarchy http://codex.wordpress.org/Template_Hierarchy#Attachment_display If you wanted to, in theory you could place a redirect into the attachment template so individual attachment views are redirected (or any number of other things you might want to do). Someone posted just that, an <code> attachment.php </code> that goes in your <code> /themes </code> folder to redirect: <code> &lt;?php header ('HTTP/1.1 301 Moved Permanently'); header ('Location: '.get_permalink($post-&gt;post_parent)); ?&gt; </code>
Unwanted media library URLs in posts?
wordpress
I've been searching for a better way to utilize the built in Thickbox function for images. I've been using my method for a few months, but I don't think it's the best way to do it. Here is the code I've been using (I don't remember where I found the code or I'd link to the article): <code> &lt;?php if (!is_admin()){ /* add a word found in your domain name */ $mydomain = ".com"; /* The css selector .entry-content a img */ $myselector = "p a img"; wp_enqueue_style('thickbox'); //include thickbox .css wp_enqueue_script('jquery'); //include jQuery wp_enqueue_script('thickbox'); //include Thickbox jQuery plugin // Function that will write js function thickbox_js(){ global $mydomain, $myselector; ?&gt; &lt;script type='text/javascript'&gt; var tb_closeImage = "&lt;?php bloginfo('wpurl'); ?&gt;/wp-includes/js/thickbox/tb-close.png"; var tb_pathToImage = "&lt;?php bloginfo('wpurl'); ?&gt;/wp-includes/js/thickbox/loadingAnimation.gif"; jQuery(document).ready(function() { jQuery("&lt;?php echo $myselector; ?&gt;").parent("a[href*=&lt;?php echo $mydomain; ?&gt;]").addClass("thickbox"); }); &lt;/script&gt; &lt;?php } add_action('wp_footer', 'thickbox_js'); // use wp_footer hook to write our generated javascript into page footer. } ?&gt; </code> Any suggestions would be appreciated. I've tried several different methods listed in tutorials, but none have worked. Thanks... To be more specific, this is the part in question: <code> &lt;?php bloginfo('wpurl'); ?&gt; </code> What I'm using now: <code> &lt;?php function add_themescript(){ if(!is_admin()){ wp_enqueue_script('thickbox',null,array('jquery')); wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0'); } } add_action('init','add_themescript'); define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true); function wp_thickbox($string) { $pattern = '/(&lt;a(.*?)href="([^"]*.)'.IMAGE_FILETYPE.'"(.*?)&gt;&lt;img)/ie'; $replacement = 'stripslashes(strstr("\2\5","rel=") ? "\1" : "&lt;a\2href=\"\3\4\"\5 class=\"thickbox\"&gt;&lt;img")'; return preg_replace($pattern, $replacement, $string); } function wp_thickbox_rel( $attachment_link ) { $attachment_link = str_replace( 'a href' , 'a rel="thickbox-gallery" class="thickbox" href' , $attachment_link ); return $attachment_link; } add_filter('the_content', 'wp_thickbox'); add_filter('wp_get_attachment_link' , 'wp_thickbox_rel'); ?&gt; </code> I thinks that's a little better, but I'm still not sure it's the optimal way. Next I need to learn how to add navigation to the ThickBox pop-up images.
What if you try adding this to your functions.php <code> function tb(){ wp_enqueue_script('thickbox',null,array('jquery')); wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0'); } add_action('init','tb'); </code> and keeping your bit of jQuery (not sure what your are needing those php variables for): <code> jQuery(document).ready(function() { jQuery("img").parent("a").addClass("thickbox"); }); </code>
Howto use WP built in Thickbox for images?
wordpress
From the past few weeks I am noticing that when I share my posts on facebook, the thumbnail is not coming, I am keeping a featured image for my posts, but when I share it on facebook it shares the link without thumbnail, I tried using several code which I found on google, but none of them works. I am using twenty eleven theme with latest WP Anyone who can help me?
You need to add Open Graph meta tags to your <code> &lt;head&gt; </code> . See <code> og:image </code> below... <code> &lt;meta property="og:title" content="35% of LinkedIn Users Check The Site Daily" /&gt; &lt;meta property="og:type" content="article" /&gt; &lt;meta property="og:url" content="http://therealtimereport.com/2011/08/05/35-of-linkedin-users-check-the-site-daily/" /&gt; &lt;meta property="og:image" content="http://therealtimereport.com/wordpress/wp-content/uploads/2011/08/LinkedIn-Users-Are-Highly-Engaged.png" /&gt; &lt;meta property="og:site_name" content="The Realtime Report" /&gt; &lt;meta property="og:description" content="Now the No.2 ranked social networking site - as of June 2011 - LinkedIn has a highly engaged, profession-focused audience, according to new research from Lab42. Based on a survey of LinkedIn users in July 2011, the data reveals that 32% of users check the site several times a week, and more than a third - 35% - check the site daily." /&gt; </code>
Facebook Share Thumbnail
wordpress
A site that was working fine previously is now getting an error, <code> Error establishing a database connection </code> I have dealt with this error while creating new wordpress sites(when there was something wrong with the <code> config </code> file). This time, the error occurred when the user upload a file to <code> public_html </code> folder. Can anyone suggest me what would have gone wrong and how to fix it ? Thanks in advance.
Did you checked your wp-config.php file? Is database name or password is changed? wp-config.php file is located on the root directory you installed wordpress. Open the file and you will see database password, username etc that wordpress use to connect your database. Check the username, passwords are correct. <code> /** The name of the database for WordPress */ define('DB_NAME', 'your_database_name'); /** MySQL database username */ define('DB_USER', 'your_database_username'); /** MySQL database password */ define('DB_PASSWORD', 'your database password'); </code>
Error establishing a database connection error on a site that was working fine previously
wordpress
Okey guys, I am little confused here. I am building a ads rotating site (specifically for jpgs/gif banners) for my client where people can add banners and create code to put in there site. My Plan So Far: Individual Ads will be a custom post type. Each ads will have a specific banner size. Ads Group: A group of ads where couple of same size ads can be added. The rotating code will be associated with the group not a single ads. So you see the Ads Group will be something that will contain the post id of the ads that associated in that group. Also i need to validate the banner size of the group (two different banner size can't be in a same group). Now what I am confused about is should i use custom post type for groups too? or i should use only taxonomy? Custom post type looks too bigger for the purpose because I only need to save the Group Ads size (125x125, 468x60 etc) and the post ids in a group item. And when i think of using taxonomy it is easy to use store the post ids (wordpress will handle that!) but how come I save the Group ads size? Is it possible to add meta values for taxonomy items? I hope you get my whole idea? Let me know if you are not clear.
Meta for taxononmies is not available out of the box, you need to create separate database table for Metadata API to work. If size is the only extra data you need and that is not going to change I'd try to use term description to hold it. Otherwise you are better off with CPT or something custom and simple.
Help need making decision. Ads rotating site on wordpress
wordpress
I have an array saved in postmata, each array key become a metakey. I want to change the code to save the whole array with one metakey. How to do that? Thanks! <code> $poddata = Array( 'pod_id' =&gt; $this-&gt;pod_id, 'url' =&gt; $this-&gt;url, 'name' =&gt; $this-&gt;name, 'description' =&gt; $this-&gt;description, 'service' =&gt; $this-&gt;service, 'status' =&gt;$this-&gt;status, 'price' =&gt; $this-&gt;price ); foreach ( $poddata as $k =&gt; $v ){ if ( get_post_meta( $this-&gt;id, $k ) == '' ) add_post_meta( $this-&gt;id, $meta_box, $v, true ); elseif ( $v != get_post_meta( $this-&gt;id, $k, true ) ) update_post_meta( $this-&gt;id, $k, $v ); elseif ( $v == '' ) delete_post_meta( $this-&gt;id, $k, get_post_meta( $this-&gt;id, $k, true ) ); } </code>
you don't need to loop through the values. Just use update_post_meta($post_ID, {key}, {array of vals}), it would do! <code> &lt;?php $poddata = Array( 'pod_id' =&gt; $this-&gt;pod_id, 'url' =&gt; $this-&gt;url, 'name' =&gt; $this-&gt;name, 'description' =&gt; $this-&gt;description, 'service' =&gt; $this-&gt;service, 'status' =&gt;$this-&gt;status, 'price' =&gt; $this-&gt;price ); //Update inserts a new entry if it doesn't exist, updates otherwise update_post_meta($post_ID, 'poddata', $poddata); ?&gt; </code> Thats it! When you fetch it for usage, do the following: <code> $poddata = get_post_meta($post_ID, 'poddata'); </code> $poddata is the array of values.
How to save an array with one metakey in postmeta?
wordpress
I have been searching for some time on how to modify the Widgets Administration Screen, i'm attempting to add the sidebar id to the wrapper elements. Current output: (produced by wordpress) <code> &lt;div class="widgets-holder-wrap"&gt; </code> Desired output: <code> &lt;div id="sidebar-id-here" class="widgets-holder-wrap"&gt; </code> In researching i've come across Stephanie Leary's blog referencing the following ticket . I would like do the same(add sidebar ids to their respective wrappers) but from the theme functions.php , ie. without modifying wp-admin/widgets.php . If anyone know how it would be great! Thanks!
I'd personally suggest an enqueue, it's preferable where possible to make use of caching and script compression. Firstly, the enqueue. <code> add_action( 'admin_enqueue_scripts', 'add_sidebar_ids_to_widget_admin' ); function add_sidebar_ids_to_widget_admin( $current_page_hook ) { if( 'widgets.php' != $current_page_hook ) return; wp_enqueue_script( 'widget-admin-jquery', get_stylesheet_directory_uri() . '/widget-admin-jquery.js', array( 'jquery' ), '1.0', true ); } </code> I placed the code in a child theme's functions file, if you're using it elsewhere you would need to replace <code> get_stylesheet_directory_uri() </code> with something else. For Child themes Use <code> get_stylesheet_directory_uri() . '/yourfile.js' </code> Parent themes Use <code> get_template_directory_uri() . '/yourfile.js' </code> Plugins Use <code> plugins_url( '/yourfile.js', __FILE__ ) </code> Then some jQuery and JS to add the appropriate IDs to the holders. <code> jQuery(document).ready(function($){ $('#widgets-right .widgets-holder-wrap').each(function(){ var slug = $(this).find('h3'); $(this).attr('id', slug.text().toLowerCase().replace( /\s/g, '-' ) + 'holder-wrap' ); }); }); </code> Does pretty much exactly the same as Bainternet's solution, just approached slightly differently.
Modify WordPress widgets Screen
wordpress
I want to create 2 new sites. One will be a simple site with a few pages -- not really a blog, but I might add a blog to it at some point. The other site will be more like a blog -- with guest posts by a number of people, and it will probably have affiliate links -- possibly Amazon links. It might also have Google Ads, display ads. For both of these sites, I might want to add things, take things away, change things, etc -- I don't know exactly what I will want to do yet -- I want to have plenty of flexibility here. And I would like a quick way to make the sites look good visually. Is Wordpress a good option for these sites? (I have a dedicated server which is currently running a site in php (which I will keep as-is) and if I understand correctly, to use Wordpress, I'd add the domains for these 2 new sites to the server, download the Wordpress installation files from wordpress.org and then upload those files to my server.) So I want to check if Wordpress is a good option for these 2 sites and for what I want to accomplish...?
WordPress can do anything you mentioned. However your question is bit too generic to be sure about anything.
Is Wordpress a good option for this...?
wordpress
Is there a PHP function that will return an array of all of my uploaded images? Or, failing that, how bout just my uploaded files? The end goal is to display a slideshow on my homepage: have it rotate through each image, one at a time. Almost like an animated gif, in an infinite loop/cycle.
uploaded files are stored as attachment post type in WordPress. Use get_posts() and query for all attachments: <code> $args = array( 'post_type' =&gt; 'attachment', 'numberposts' =&gt; -1, 'post_status' =&gt; null, 'post_parent' =&gt; null ); $all_attachments = get_posts( $args ); </code> EDIT - you can also set <code> post_mime_type </code> in get_posts to get all of type 'image/jpeg' for example.
Is there a function to list all uploaded images? How can I add one?
wordpress
Is there an argument to define how many posts ago will be displayed in "recent" posts. Could I add something to this and define a specific number of posts ago to start the loop? <code> $args = array( 'numberposts' =&gt; '5' ); $recent_posts = wp_get_recent_posts( $args ); </code> So for example I have a page of archives with their excerpts for the last 5 posts. In the sidebar I would like to show other posts from that category, starting with 6 posts ago.
<code> wp_get_recent_posts </code> basically uses <code> WP_Query </code> , so you can use the <code> offset </code> parameter. So something like, <code> $args = array( 'numberposts' =&gt; '5', 'offset' =&gt; 5 ); </code> Reference: http://codex.wordpress.org/Class_Reference/WP_Query#Offset_Parameter
Show recent posts starting at a specific number archive
wordpress
I'm trying to create a new user after someone fills out a form. I'm using <code> wp_create_user </code> to do so. A user is being created properly, but, for whatever reason, no password is being submitted to the <code> users </code> table. It's simply a blank value. First of all, I should note that, unfortunately, for this project I'm on 3.1.3 and there is very little chance that I'd be able to use 3.2.1. I've checked to make sure that the password is correct up to the point that it is passed to the <code> wp_create_user </code> function and the value is as expected. I've also gone so far as to trace the password to the <code> wp_insert_user </code> function. It passes through the <code> wp_hash_password </code> function and comes out as a 34 character password hash. I then checked to see what the value of the password is before the <code> $wpdb-&gt;insert </code> method is executed to insert the user. The password is still the beautiful hash, not an empty value. I then kept on down the rabbit whole into the <code> _insert_replace_helper </code> method of the <code> $wpdb </code> class. The data fed to that function was just fine; however, the function returns: <code> return $this-&gt;query( $this-&gt;prepare( $sql, $data ) ); </code> I went to look at the <code> prepare </code> method and it is defined as: <code> function prepare( $query = null ) { // ( $query, *$args ) </code> Yes that little comment is from the actual code. When I saw it, I thought the previous dev had made this alteration. I was initially furious until I diffed it against the real file and found it to be identical. So, my confusion here is that the <code> _insert_replace_helper </code> method is calling the <code> prepare </code> method and sending it two arguments when it expects 1. What in the world is going on here? Ultimately, I have two questions: 1) Why isn't my password being sent to the database 2) What is going on with the <code> _insert_replace_helper </code> method sending two arguments to the <code> prepare </code> method? I should note that the function I'm using to add the user looks like: <code> // Function for registering user function gov_register_user($name, $password, $email, $company, $phone) { // If user is registered, don't register him/her again, but return true so no error is flagged if(email_exists($email)) return true; // If any of the necessary fields are not filled, return false if($name == '' || $password == '' || $email == '') return false; // It's now safe to register the user $user_id = wp_create_user($name, $password, $email); if($user_id) { // Email user add_filter('wp_mail_content_type',create_function('', 'return "text/html"; ')); wp_mail($email, 'Registration', get_mail_user_registration($name, $email)); // Set meta fields set_cimyFieldValue($user_id, 'COMPANY', $company); set_cimyFieldValue($user_id, 'PHONE', $phone); // Log user in $gov_creds = array( 'user_login' =&gt; $name, 'user_password' =&gt; $password, 'remember' =&gt; true ); wp_signon($gov_creds, false); return true; } else return false; } </code>
PHP support variable-lengths argument lists . Simply put you can pass as many additional arguments as you want to any function and PHP won't even blink. If you look at the source of <code> $wpdb-&gt;prepare() </code> method it simply fetches all arguments with <code> func_get_args() </code> into variable and works with that. It doesn't care about function signature (older or current either) at all. So I think this is completely unrelated to your password issue, I'd try poking that plugin. PS 3.2 is not that much different from 3.1, why problem upgrading? Running outdated version is trouble in the long run.
wp_create_user not properly entering password
wordpress
Is there a way to select and display the last X approved comments regardless of which posts or categories they belong to ? I just want to show on my home page the last comments added on my site, but I can't find anywhere how to do that.
A slightly more complete and less abrupt answer. <code> &lt;?php $args = array( 'status' =&gt; 'approve', 'number' =&gt; '5' ); $comments = get_comments($args); foreach($comments as $comment) : // display any of the following indexes as you'd like var_dump($comment); endforeach; ?&gt; </code>
Display last comments on home page
wordpress
I have a blog which uses custom post type 'aside' for aside posts. Now that wordpress has custom post formats, I want to use the 'aside' post format instead. Is there a way to convert post typess to post formats? I'm looking for code/tool similar to wordpress's in-built tool which lets one convert from categories to tags.
There are a couple of plugins available that will allow you to do this. http://wordpress.org/extend/plugins/post-type-convertr/ or http://wordpress.org/extend/plugins/convert-post-types/ should get the job done for you.
How does one go about converting custom post type to post format?
wordpress
I would like to remove screen options and help links in my admin area. How to remove that thing?. This is what i want to be removed. Thanks.
There are several plugins that can do that: Adminimize , you can remove it even on role base Admin Trim Menu
How to remove screen options and help links in the admin area?
wordpress
On my website http://filmblurb.org , all the posts and everything on my home page are missing. Can you anybody tell me how to fix this? Thanks! (If it helps, I'm using Wordpress 3.2.1.)
I cannot see any missing content. Are you sure you weren't just having server issues at the time of posting this? Did you check it in other browsers? Having said that, this is not a real question and I have voted to close.
Why is my content missing from homepage?
wordpress
I'm currently developing a plugin and the chances are that I will more than likely release it on the public plugin repository so others can use it. The plugin will be using an API and to use this API you need to pass a username and password. So my plugin needs to store these login credentials in the database. I don't want to store these in plain text although the API needs them in plain text. So my question is how do I store these sensitive bit of information? Hashing is out, so it has to be some sort of encryption. In WordPress is there a unique key that can be used that will differ from blog to blog? What php functions should I use to encrypt and decrypt? I'm looking for functions that will more than likely work on all WP installs.
While I agree with the previous answers, to answer the question you actually asked, what comes to mind is to use one of these constants for wp-config.php: define('AUTH_KEY', 'redacted'); define('SECURE_AUTH_KEY', 'redacted'); define('LOGGED_IN_KEY', 'redacted'); define('NONCE_KEY', 'redacted'); They are meant to be unique across wordpress installations - and are about the only options for pre-existing keys to be found in wordpress. Alternate would be to add your own similar constant that is built by hashing one of them against the admin email address or similar - and then storing that in a hidden setting option -- to protect against losing your key if someone accidentally modifies the keys after your plugin is installed. The danger is, that if they were not made unique on the initial install, but the admin / site owner decides to rectify the failure after the fact, they shouldn't accidentally break your password encryption. As for encryption / decryption functions - a quick Google search returns the following listing with code that appears to fit the bill: http://maxvergelli.wordpress.com/2010/02/17/easy-to-use-and-strong-encryption-decryption-php-functions/ function encrypt($input_string, $key){ $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $h_key = hash('sha256', $key, TRUE); return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $h_key, $input_string, MCRYPT_MODE_ECB, $iv)); } function decrypt($encrypted_input_string, $key){ $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); $h_key = hash('sha256', $key, TRUE); return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $h_key, base64_decode($encrypted_input_string), MCRYPT_MODE_ECB, $iv)); } Here's some documentation of the AES encryption used here: http://www.chilkatsoft.com/p/php_aes.asp
How to store username and password to API in wordpress option DB?
wordpress
i need to filter count based on a date and post_status = 'publish', how to write a query to filter, as far as now i have filtered based on date, what is the query need to filter based published post. $table1 = $wpdb-> prefix.'posts'; $sql = 'SELECT COUNT(ID) AS count FROM '.$users_table1.' WHERE DATE(post_date) &lt; "'.date('Y-m-d',time()).'"'; $result = $wpdb-> get_var($sql); iam stuck with this, do anyone know this?
You can add this to the WHERE clause, just after your filter by post_date: <code> AND post_status = "publish" </code>
query for filtering published posts?
wordpress
I have set a page to be password protected in the admin, but for some reason WP is not asking for the password when viewing the page. It definitely isn't a plugin as I have confirmed the behaviour with the plugin folder renamed. I have been testing it in Chrome w/incognito. The page is using a custom template, which may be the problem? No other templates I have looked at though seem to display any password logic.
The answer to this question was simply that the built-in password protection does not apply if you are using a custom template that doesn't include <code> the_loop() </code> . Lesson learnt.
Password Protected page not asking for a password
wordpress
I'd like to be able to enable/disable plugins on a per-site basis in multisite, similar to the way that themes are per-site configurable. Is this currently possible? (For instance, I don't particularly want people seeing the Domain Mapping plugin but want them to be able to enable Gravity Forms.)
Multisite Plugin Manager The essential plugin for every multisite install! Manage plugin access permissions across your entire multisite network.
Can I enable/disable/hide plugins on a per-site basis in multisite?
wordpress
Sometimes it's nice to have admin on a different host (admin.mysite.com) then the actual site (www.mysite.com). If admin.mysite.com is not publicly accessible, then images attached to posts on admin.mysite.com will not be accessible on www.mysite.com since the url to the attached image is absolute and contains the domain (admin.mysite.com). Is there any way to fix this? The nicest way would be if the url to an attached media would be relative and not absolute.
I found another way of doing this. I added the following to functions.php: <code> function yoursite_get_relative_attachment_path($path) { $paths = (object)parse_url($path); return $paths-&gt;path; } function yoursite_wp_handle_upload($info) { $info['url'] = yoursite_get_relative_attachment_path($info['url']); return $info; } add_filter('wp_handle_upload', 'yoursite_wp_handle_upload'); function yoursite_wp_get_attachment_url($url) { return yoursite_get_relative_attachment_path($url); } add_filter('wp_get_attachment_url', 'yoursite_wp_get_attachment_url'); </code> This way wordpress stores the relative URL in the db. For more detailed instructions see the blog where I learned about this .
Having admin on different host breaks attached images
wordpress
A new site i'm making is going to use extensive use of the categories, so here's what i'm trying to accomplish: Main Category Name (Link) List of Sub Categories (All Links) When i'm on a sub-category page I want it to look like the Main Category page just with the sub-categories highlited. Is that possible?
That's damn simple, see here: http://codex.wordpress.org/Function_Reference/get_categories . The sample downhere should work: <code> $kids = get_categories(array('child_of'=&gt;get_query_var('cat'))); </code>
Printing out Category and all Category Children on category.php
wordpress
took a look at the questions but I couldn`t find a similar one. I need to change the custom error messages that are displayed when user tries to login with a wrong username or password. Like, change this: " ERROR : The password you entered for the username %1$s is incorrect. Lost your password?" to this "Wrong information" (just an example) I tried to use the "add_filter" but I`m not familiar with it, so, any help will be appreciated! Thanks
you can do that using <code> login_errors </code> filter hook and here is how: <code> add_filter('login_errors','login_error_message'); function login_error_message($error){ //check if that's the error you are looking for $pos = strpos($error, 'incorrect'); if (is_int($pos)) { //its the right error so you can overwrite it $error = "Wrong information"; } return $error; } </code> update: i just tested the code and it works fine just pasted the code in my theme's functions.php file without changing anything with the .po file
Change login error messages
wordpress
I am trying to run a script when a user publishes / updates a post. I am using the filter: wp_insert_post_data The problem I am having is the script is a php file outside of WordPress but on the same site (It works fine if i go direct to it) that just needs to be run. I tried to include the file using the filter but that stopped the post being updated for some reason. This is my current code: <code> function updateFeed( $data , $postarr) { include 'jobsfeed.php'; return $data; } add_filter( 'wp_insert_post_data' , 'updateFeed' , '99', 2 ); </code> Is there any way to be able to run this script? EDIT: It does seem teh file is being run but for some odd reason it is not outputting the custom field values. It is a simple php file with a loop using wp_query and it works fine when I go direct to it. - any ideas what it could be? EDIT: Figured out why teh custom post types were not working i had to change how the script retrievd an id. Now I have one final thing to fix for some reason when the script runs when a page is edited the xml output by the script is the previous save data. SO it means i have to press save twice to make my new edits appear. Is it getting the revisions or being triggered too early perhaps?
It looks like it could be because the filter cannot find the include file. Try using: <code> include( ABSPATH. "/path/to/file/jobsfeed.php" ) </code>
run script on publish
wordpress
I want to allow commas in tag names? For example, <code> "hello, world" </code> or <code> "portland, or" </code> but Wordpress keeps separating them. I can do it from the categories page: And it shows up fine. But anything added from the posts sidebar does not show up ok here: There is some discussion on it here: http://core.trac.wordpress.org/ticket/14691 but looks like it may not get solved, at least for a while. In the meantime, I'm looking for an easier solution than adding categories from the categories page. I've tried searching plugins, and didn't see any that would be helpful. There are a few that deal with replacing commas with other characters when displaying a list of categories, or tags, but I don't see any plugins that allow the user to replace the default separator. I don't care if I have to patch the core myself. Ideally I could write a plugin, but after looking through some of the code I can't figure out where this gets handled. Does anybody have a solution, or tips on what functions and javascript to start hacking? I'm not sure where to start looking in the code.
No core hacking needed -- thanks to: HOOKS. Hooks allow to fix the issue with a nice combination of a filter replacing "--" by ", " before output and an "if" loop to make sure the output is not also filtered for the admin interface :) and finally you, saving all your tags with comma in the format "Fox--Peter" instead of "Fox, Peter" Here's the code: <code> // filter for tags with comma // replace '--' with ', ' in the output - allow tags with comma this way // e.g. save tag as "Fox--Peter" but display thx 2 filters like "Fox, Peter" if(!is_admin()){ // make sure the filters are only called in the frontend function comma_tag_filter($tag_arr){ $tag_arr_new = $tag_arr; if($tag_arr-&gt;taxonomy == 'post_tag' &amp;&amp; strpos($tag_arr-&gt;name, '--')){ $tag_arr_new-&gt;name = str_replace('--',', ',$tag_arr-&gt;name); } return $tag_arr_new; } add_filter('get_post_tag', 'comma_tag_filter'); function comma_tags_filter($tags_arr){ $tags_arr_new = array(); foreach($tags_arr as $tag_arr){ $tags_arr_new[] = comma_tag_filter($tag_arr); } return $tags_arr_new; } add_filter('get_terms', 'comma_tags_filter'); add_filter('get_the_terms', 'comma_tags_filter'); } </code> Maybe some additional details in my blog post to that topic help as well .. http://blog.foobored.com/all/wordpress-tags-with-commas/ Greets, Andi
How can I allow commas in tag names?
wordpress
Is there a way to import users from another wordpress site? Both sites are new. I just don't want to go through the trouble of adding the same users profile information and password.
I think you have two options (third if you find any plugins). I think if you export data from one WP, the users are also copied. The drawback is that you have to import all the content as well. The second option is to export the users from MySQL using PHPMyAdmin. Just export the user table. If you want to include privilidges as well, you have to export wp_usermeta as well.
Importing users? From another wordpress site
wordpress
I am developing WordPress plugin.This plugin has own login system.Which means users can register into the system. Then they can login. if the user login, i want to redirect them to their own profile page.This page should not be accessible while user is in logout or plugin is in inactive.So how can i create page through plugin. Thanks
If the page needs to be added and available on the front end, you can use wp_insert_post() to create the page, the use a conditional to only display it if the user is logged in: <code> if(is_user_logged_in()) { // display content } </code>
How can i create page through plugin
wordpress
I'm trying to use the function get_the_tags() from outside the 'loop'. I understand this can be achieved by using the post ID like <code> get_the_tags($postID) </code> . Does anyone know how I can get the post ID from inside a wp_insert_post_data function? I've tried using 'guid' which is suggested here , although I've had no luck. I'm also not sure that's even the post ID. Any help with this will be appriciated. Thanks. EDIT: Here's the code I'm working with: <code> function changePost($data, $postarr) { $postid = $postarr["ID"]; $posttags = $postarr['tags_input']; // This doesn't work. $content = $data['post_content']; $subject = $data['post_title']; if($data['post_status'] == 'publish') { sendviaemail($content, $subject, $postid, $posttags); } return $data; } add_filter('wp_insert_post_data','changePost','99',2); </code> As you can see, I want to send the post ID, post tags, content and the subject to another function called "sendviaemail". Everything is okay, except I don't know how to get the tags from the post.
In the following, '10' is the priority that <code> my_func </code> gets called and '2' is the number of arguments that <code> my_func </code> accepts. The latter is important , since the <code> add_filter </code> function defines the default as 1, but the <code> wp_insert_post_data </code> filter hook sends two arguments. If you don't set this as 2 you won't get the second argument. <code> add_filter("wp_insert_post_data", "my_func", 10, 2); </code> Now make your function... <code> function my_func($data, $postarr){ //at this point, if it's not a new post, $postarr["ID"] should be set //do your stuff... return $data; } </code> EDIT--- based on your added code above If you don't need to modify the post's <code> $data </code> before the post is saved then you're using the wrong hook. Use the <code> save_post </code> action hook instead. This gets called after the post is saved and all the taxonomies are saved. So you don't have to worry about whether new tags have been added. It sends two arguments to your function: the ID of the post and the post itself as an object. <code> add_action("save_post", "my_save_post"); function my_save_post($post_id, $post){ if ("publish" != $post-&gt;post_status) return; $tags = get_the_tags($post_id); //an array of tag objects //call your email func etc... } </code>
Getting post id from wp_insert_post_data function?
wordpress
I have a form that creates a new user by using: <code> wp_create_user() </code> This works, but after this I want to auto log in the user. I tried using: <code> $creds = array(); $creds['user_login'] = 'username'; $creds['user_password'] = 'password'; $creds['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) { $msg = $user-&gt;get_error_message(); die($msg); } else { $output_form = true; } </code> But this creates a "headers already sent" error message because it's not at the top of the page. Is there a way to auto log in the user after I have created the user?
Here is a function I wrote that hooks into the gravity forms create user form but it can be added to whatever action hook your wp_create_user function is attached to. <code> function my_auto_login( $user_id ) { wp_set_auth_cookie( $user_id, false, is_ssl() ); wp_redirect( admin_url( 'profile.php' ) ); exit; } </code> The important part is <code> wp_set_auth_cookie </code> . This has to fire after the user is the best (only?) way to auto login a user without filling out the login form.
Set user after wp_create_user?
wordpress
I'm employing custom widgets for my client because it's easy and they have several menus they need to create specific to site sections. I then want to allow them to add to the custom menu dynamically using widgets (I create the spaces needed for the widget and they drag and drop the menus into that widget bucket). I tried using the following code but when the left nav sidebar is supposed to load, the page stops loading. <code> if (is_page( 'sport-fitness' ) || '269' == $post-&gt;post_parent){ //menu for Sport &amp; Fitness pages &lt;div id="seventh" class="widget-area" role="complementary"&gt; &lt;?php dynamic_sidebar( 'sidebar-7' ); ?&gt; &lt;/div&gt;&lt;!-- #second .widget-area --&gt; }elseif(is_page( 'eat-smart' ) || '118' == $post-&gt;post_parent){ //menu for Eat Smart pages &lt;div id="eighth" class="widget-area" role="complementary"&gt; &lt;?php dynamic_sidebar( 'sidebar-8' ); ?&gt; &lt;/div&gt;&lt;!-- #second .widget-area --&gt; }else{ //default menu } </code> The custom menus need to show up on all child pages (but not the parent page because that uses a different layout). What am I doing wrong with the above? I got this to work: <code> if (is_page( 'sport-fitness' ) || '269' == $post-&gt;post_parent){ //menu for Sport &amp; Fitness pages wp_nav_menu( array('menu' =&gt; 'sport-fitness' )); }elseif(is_page( 'eat-smart' ) || '118' == $post-&gt;post_parent){ //menu for Eat Smart pages wp_nav_menu( array('menu' =&gt; 'eat-smart' )); }else{ //default menu } </code> But then I'm stuck without the headers that the widgets provide (which they want). For example: SPORT &amp; FITNESS Home Link 1 Link 2 Link 3 Help would be greatly appreciated. I've been trying to figure this out for a couple days now and it's a blocker to finishing their site. TIA!
if you want to show the menus only on child pages then you need to change your conditional statement: <code> global $post; //only on children of 269 if ('269' == $post-&gt;post_parent){ //menu for Sport &amp; Fitness pages ?&gt; &lt;div id="seventh" class="widget-area" role="complementary"&gt; &lt;?php dynamic_sidebar( 'sidebar-7' ); ?&gt; &lt;/div&gt;&lt;!-- #second .widget-area --&gt; &lt;?php //only on children of 118 }elseif( '118' == $post-&gt;post_parent){ //menu for Eat Smart pages ?&gt; &lt;div id="eighth" class="widget-area" role="complementary"&gt; &lt;?php dynamic_sidebar( 'sidebar-8' ); ?&gt; &lt;/div&gt;&lt;!-- #second .widget-area --&gt; &lt;?php //everything else including parent pages }else{ //default menu } </code>
Custom Menus, Widgets & Conditional Statements
wordpress
I followed this tutorial to create custom metaboxes. It seems like qtranslate enables you to use shortcodes almost everywhere. For example: Post titles: <code> &lt;!--:en--&gt;Cheng Feng Enterprises&lt;!--:--&gt;&lt;!--:zh--&gt;鄭峰企業&lt;!--:--&gt;&lt;!--:es--&gt;Cheng Feng Compania&lt;!--:--&gt; </code> Widgets: <code> [:en]My name is Alex Chen. I provide Spanish-English-Chinese translation services in Taiwan. &lt;a href="mailto:[email protected]"&gt;&lt;strong&gt;I'm available for hire&lt;/strong&gt;&lt;/a&gt;. [:zh]我的名字是亞歷陳。 我提供西班牙語 - 英語 - 中國 在台灣的翻譯服務。 &lt;a href="mailto:[email protected]"&gt;&lt;strong&gt;我可供租用&lt;/strong&gt;&lt;/a&gt;. </code> None of these methods work for custom metaboxes. Has anyone successfully integrated qtranslate with custom metaboxes?
recently I used qtranslate with metaboxes. In my function.php I added code for display n metaboxes by n languages, in the save data event, I use qtranslate_join, this function make the magic.
Has anyone successfully integrated qtranslate with custom metaboxes?
wordpress
I'm creating some custom templates and I keep running in to a problem where I get'Page not found'. After a bit of debugging, I discovered that I only get this if my URL contains <code> www.mysite.com/custom_page/?name=donkey_boy </code> . If I use <code> www.mysite.com/custom_page/?full_name=donkey_boy </code> , the page loads as it should. Does that mean that <code> name </code> is a reserved word?
I guess this'll solve your query... WordPress Reserved Terms. Just search for 'name', it's there.
Is 'name' a reserved word in URL's?
wordpress
having problems with filtering a posts attachments by tag... It worked fine until i added the tag__in arg (and other variations of it). <code> $vidArgs = array( 'tag__in' =&gt;5, 'post_type' =&gt; 'attachment', 'post_parent' =&gt; $post-&gt;ID, 'post_mime_type'=&gt;'video/quicktime', 'posts_per_page'=&gt;20 ); $videos = get_posts($vidArgs); foreach ($videos as $vid) { ///.... </code> pointers / advice appreciated! UPDATES it is odd. It just doesn't work with media tags! Added testtag to a post and it comes up. There must be a way to get attachments by tags? Otherwise what's the point? The functionality is in wp admin from the Media Tags pane... <code> $argsc = array( /* 'tag' =&gt; 'commercials,testtag', */ 'tag__in' =&gt; array(5,11), 'post_type'=&gt;array('post','page','attachment'), 'post_status'=&gt;'any', /* 'post_parent'=&gt;$post-&gt;ID, */ 'posts_per_page'=&gt;20 ); $the_queryB = get_posts( $argsc); echo count($the_queryB).", &lt;pre&gt;"; print_r($the_queryB); </code>
found n easy way of doing this now! Getting images by 'your case' tag and logged in user. <code> $args = array( 'post_type' =&gt; 'attachment', 'author' =&gt; $current_user-&gt;ID, 'post_status' =&gt; 'inherit', 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'media_tag', 'terms' =&gt; 'yourcase', 'field' =&gt; 'slug', ) ) ); $attachments = get_posts($args); </code> UPDATE. media_tag seems to be a custom taxonomy added by the file gallery plugin.
attachments with tags and get_posts
wordpress
Is it a bad idea to set your themename and shortname as variables to be used in the various functions of a theme? Example: <code> $themename = mytheme; $shortname = mth; /** * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. */ function toolbox_page_menu_args($args) { // some code } add_filter( 'wp_page_menu_args', $themename . '_page_menu_args' ); </code>
You can do it easier and without polluting the global namespace: <code> get_option('template'); </code> gives you the (parent) themes name. If you want the child themes name, use <code> get_current_theme(); </code> . You could also use a constant across your theme files: <code> define( 'YOUR_PREFIX-THEME_NAME', get_current_theme() ); </code>
Using $themename Variables
wordpress
Is there a way to show a 404 page if the current logged in user does not have the right clearance to view the page? I am looking for a PHP method, something like <code> if( !current_user_can('administrator') ) { show_404(); exit(); } </code> I have thought about using a redirect, but I would like to keep the url the same.
I was able to display a 404 error by using the following code in my header. <code> &lt;?php global $wp_query; $wp_query-&gt;set_404(); status_header( 404 ); get_template_part( 404 ); exit(); ?&gt; </code> To break it down: <code> $wp_query-&gt;set_404() </code> : tells the wp_query this is a 404, this changes the title <code> status_header() </code> : sends a HTTP 404 header <code> get_template_part() </code> : displays the 404 template
Redirect Restricted Page to 404
wordpress
How can I link to another WordPress page but move variables to it as well (preferably not through the address bar)? For instance, I have on one page a list of shops in which a user should be able to click on a shop, which would then open the shop page with the correct data. So the shop's id needs to move from the shops list page to the shop page.
you could <code> POST </code> the shop id to the target page. otherwise- cookie, session. or just fetch it on the list page via ajax. edit - a simple post request via a form: in your source page: <code> &lt;form action="b.php" method="post"&gt; &lt;input type="hidden" name="id" value="42" /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code> in the target page b.php: <code> &lt;?php if( isset($_POST['id']) ): echo $_POST['id']; endif; </code>
Moving variables from one page to another
wordpress
I looking for a simple Wordpress e-commerce plugin which will just associate a downloadable product to a post (here a custom post type) and handle the payment with Paypal and the download page. There are a lot of different plugin but they always provide a complex catalog, create a lot of useless page and don't provide a simple way to add in my post a simple "buy now" button which go directly to payment. Are you aware of a plugin which meets these needs?
You may want to consider Cart66 . I bought a single site license a few weeks back as I was looking for something along a similar line to you. It doesn't force a bunch of bespoke templates on you, instead, you have to create each product through a custom post (which is what you are doing anyway). However the big benefit of this is that you have near total control over how your product pages look. Cart66 comes in two flavours - free ( Cart66 Lite ) or if you want more features and support you can try one of the site license options. So far I've found it to be very straightforward and more flexible than a lot of the competition. Hope this helps
Looking for a simple e-commerce plugin
wordpress
When we setup the timezone in wordpress settings page. Does it changes the server time? If I call <code> time(); </code> does it returns unix time according to timezone setup in the settings page? I have checked this page here stackexchange-url ("How to get WordPress Time Zone setting?") So, if i need to show suppose the current time of a neighborhood site what modification i have to do with the output of <code> time(); </code> function? The php <code> time(); </code> returns the time in the server. So is that depends on where my host belongs? Thanks in advance!
WordPress tries to set PHP environment to UTC timezone. Usually it is more reliable to use time zone-aware WP functions, such as <code> current_time() </code> , rather than vanilla PHP functionality.
Wordpress time queries
wordpress
I need to show my users cumulative posts and members registered count by date. It has to be displayed in an array format like this for posts <code> array(array(2011,08,02), 500) array(array(2011,08,03), 520) array(array(2011,08,04), 540) array(array(2011,08,05), 560) array(array(2011,08,06), 580) </code> the same case for members iam using wordpress.com stats to for statistics, i cant figure out how to do this, could anyone help me...
Here is a very crude script I've knocked up to get what you are after: <code> &lt;?php require('wp-blog-header.php'); $posts = get_posts('numberposts=-1&amp;order=ASC'); $posts_times = array(); foreach ($posts as $post) { $post_time = strtotime($post-&gt;post_date); $offset = $post_time % (60*60*24); $post_time -= $offset; $posts_times[$post_time]++; } $keys = array_keys($posts_times); $running_count = 0; $end_data = array(); for($i = $keys[0]; $i &lt;= $keys[(count($keys)-1)]; $i += (60*60*24)) { $running_count += $posts_times[$i]; $end_data[] = array( array(date("Y", $i), date("m", $i), date("d", $i)), $running_count ); } echo "&lt;pre&gt;"; print_r($end_data); ?&gt; </code>
How to create a cumulative posts and members count
wordpress
I want to move my blog to wordpress.com but I do run my own nameservers and I need to do it. Is it possible to use wordpress.com pointing the IPs of the hostname to it but not switching the nameservers?
Here is what WordPress.com have to say on using your domain with them: http://en.support.wordpress.com/domain-mapping/map-existing-domain/ From there they are clearly saying to use their nameservers. This will because they have a number of IP address and any one of them could be the one hosting your website. Therefore they cannot reliably give you the IP address to where you would point your web traffic. Also on top of that IP address can change without any notice and then all of a sudden your website would go offline. I'd really recommend that you stick with using their nameservers. I presume that you are using your own nameservers because you want to control other DNS and MX entries? Well if thats the case did you know WordPress.com comes with a control panel so you can setup additional DNS and MX entries? If you still cannot use their nameservers then what you can do is set up a free account first and ping your free account domain "example.wordpress.com" and get the IP of where it is hosted. Once you have that upgrade your website to domain hosted and point web traffic to the IP you obtained. I cannot vouch if this will work but its a start.
Is it possible to use wordpress.com with a custom domain without switching nameservers?
wordpress
I'd like to make that all my posts in the category A belong also to category B (so after that they would belong both to A and B), is there any plugin or MySQL query that could allow me to do that easily?
You can bulk edit posts in the admin. I have never tried more than 500 or so but you can display 999 per page. To have more than the default 20 click screen options. Click posts--> filter by Category A Click Edit---> select all posts ( clicking top square next to "title")--> Apply Click Category B and Update.
How to make that all posts with a category belong also to another
wordpress
I don't want to have to make use of a destination url, so ideally I would like to be able to add the onclick="_gaq.push(['_trackPageview', '/G1/whatever']);" event to the submit button on the form.
This seems to be a valid answer: Use Contact Form 7 . In the "Additional Settings" box enter the following: <code> on_sent_ok:"_gaq.push(['_trackPageview', '/G1/whatever']);" </code> Where <code> /G1/whatever </code> is the Goal URL you set on your Google Analytics options page.
Is there a WordPress form plugin that can easily be configured for Google Analytics goals?
wordpress
i'm hosting several sites. they all have the same base theme that i need to install. I want to develop this theme and have them updated on all the sites simultaneously. I have the following folder structure <code> /theme/ \ mytheme /domain/ \ foo.com \ foobar.com \ foosite.com </code> Would there be any issue with symlinking each site with my theme into each site's <code> wp-config/theme/ </code> folder? Not interested in multisite. Had to developed sites seperately.
That will work fine - just make sure they all have read and write access to that shared folder. The symlink command should be: <code> ln -s </code> StackOverflow question: stackexchange-url ("Can two different WordPress blogs on the same server use a common theme folder?")
Install theme on multiple domains
wordpress
Is it possible to create a local wordpress network install on a mac (10.6) using mamp with subdomains? I have tried following some instructions I came across while googling, but apache seems to get hosed when I create virtual hosts. I came across another set of instructions that said only subdirectories will work on a local install. Does anyone know which one of these is the case and have you come across a good set of instructions for how to do it? Thanks,
This tutorial was just published at DevPress by Patrick Carey: http://web.archive.org/web/20111222021406/http://devpress.com/blog/how-to-setup-subdomains-for-a-local-wordpress-network It should help you. It has been written for Windows but you should be able to translate it into "Mac"
Can you create a local wordpress network / multisite install on a mac with subdomains?
wordpress
I'm working on a site which is not attached to a domain name yet, so I access to it through an ugly URL like old_server.something.myprovider.co.uk/.../.../ My provider moved me to a new server so I now have to type : new_server.something.myprovider.co.uk/.../.../ Problem is, when trying to access wp-admin, WordPress performs some sort of redirection to the old address and of course it doesn't work anymore. So I can't access the login page. Is there a way to change the server URL in WordPress without accessing the dashboard ?
Yes cou can change it by accessing the database of your wordpress. It's located in the <code> wp_options </code> table of your wp' database. You'll have to change two values; the <code> siteurl </code> (line 1) and the <code> home </code> (line 37). You can access it through the admin panel of your host and/or sometimes directly by typing in your browser the <code> DB_HOST </code> value you entered for the installation of the blog, now written in your <code> wp_config.php </code> file at the root of your site. Then just use the login and password also written in this file. This should do it. EDIT: i recommend the use of this kind of plugin to clean completely the database to change all your http://yourolddomain.com/whatever/ to http://yournewdomain.com/whatever/ .
Can't login after my site was moved to a new server
wordpress
Example: I'm trying to modify an instantiation of WP_Query by using the <code> posts_orderby </code> filter like so: <code> add_filter('posts_orderby', 'favorites_orderby'); $new_query = new WP_Query($args); remove_filter('posts_orderby', 'favorites_orderby'); </code> the <code> favorites_orderby() </code> function is like so: <code> function favorites_orderby($post_in){ if(is_array($post_in)) $post_in_str = implode(',', $post_in); return $post_in_str; } </code> <code> $post_in </code> is an array that changes based on a previous, separate db query, so I need to be able to pass it into the <code> favorites_orderby() </code> function. Basically it's an array of post IDs that need to get fed to the WP_Query instantiation's <code> ORDER BY </code> parameter so that the resulting db request is set like so: <code> ORDER BY FIELD(ID, 6, 18, 90, 12) </code> . Everything works except passing the array of post IDs ( <code> $post_in </code> ) to the <code> favorites_orderby() </code> Any help would be greatly appreciated!
No, filters get arguments based on the call to the filter. Basically, filters get their inputs from the apply_filters function call. If you want to pass in data via another means, use a global variable or wrap the code and the data you want to use in an instance of a class.
Is it possible to add an argument to a custom function added to a filter hook?
wordpress
I have a tricky situation.... I'd like to check for a cookie. If it doesn't exist then then redirect to an internal wordpress page, and set a cookie. And then carry on browsing the site. But i get stuck in a loop if the url doesn't exist. This is what i have so far...any help would be great. <code> function cookiebasedredirect() { // WHEN YOU HAVE FOUND YOUR COOKIE if ( !isset($_COOKIE["sevisitor"])) { setcookie('sevisitor', 1, time()+1209600, "/", "http://localhost/child/", false); // GRABS THE CURRENT PAGE NAME - THIS IS ALSO KNOWS AS THE PAGE/POST SLUG $pagename = get_query_var('pagename'); // PAGE CHECK SO THAT YOU ARE NOT IN AN INFINITE LOOP // IN THIS SAMPLE MEDIA-GALLERIES IS THE PAGE YOU WANT TO BE // REDIRECTED TO IF A COOKIE IS NOT SET, BUT ONCE YOU GET THERE // MAKE SURE WORDPRESS DOESN'T EXECUTE THE REDIRECT if( $pagename != "about-myself") { wp_redirect( get_site_url().'/about-myself' ); exit; } else { } } else { }} add_action("template_redirect", "cookiebasedredirect"); </code>
why not use the <code> init </code> action hook: <code> function has_my_cookie() { if (!is_admin()){ //Check to see if our cookie is set if not redirect to your desired page and set the cookie if ( !isset($_COOKIE["sevisitor"])) { //setcookie setcookie('sevisitor', 1, time()+1209600, "/", "http://localhost/child/", false); //Redirect wp_redirect( get_site_url().'/about-myself' ); exit; } } } add_action('init', 'has_my_cookie'); </code>
Wordpress Redirect based on the prescence of a cookie
wordpress
I have an older theme that I've modified to support threaded comments. I would like the individual admins in my multisite install to be able to choose whether threaded comments are enabled. However, I'd like to restrict the ability to choose the maximum number of levels to super admins. Looking at the capabilities, it seems that all capabilities for the settings screen are grouped together as one capability . Is it possible to restrict just this single option so that it is forced to be the same static value across the entire blog network?
There is only one hook for threaded comments depth - <code> thread_comments_depth_max </code> and it sets max value for depth ( default is 10 ), you can use this filter and set max depth fox non-Super Admins number that you want. <code> if ( ! current_user_can( 'manage_network' ) ) { mamaduka_thread_comments_depth_max( $maxdeep ){ return 5; // or any number you want } add_filter( 'thread_comments_depth_max', 'mamaduka_thread_comments_depth_max' ); </code>
How can I restrict changing the max nested comment levels option to super admins?
wordpress
Using the following code in order to display custom field value, how can I automatically make it into a hyperlink? <code> &lt;?php $custom_fields = get_post_custom($post_id); //Current post id $my_custom_field = $custom_fields['website']; //key name foreach ( $my_custom_field as $key =&gt; $value ) echo $key . " =&gt; " . $value . "&lt;br /&gt;"; ?&gt; </code> Presently if website value is set to http://www.abc.com then it would display http://www.abc.com instead i'd like for it to display as Click Here where it hyperlinks instead.
<code> &lt;?php $custom_fields = get_post_custom($post_id); //Current post id $my_custom_field = $custom_fields['website']; //key name foreach ( $my_custom_field as $key =&gt; $value ) echo $key . " =&gt; &lt;a href='" . $value . "'&gt;Click Here&lt;/a&gt;&lt;br /&gt;"; ?&gt; </code>
Display custom field value as a hyperlink
wordpress
I just want to add author gravatar near the name of the author. I know that I have to add something in the single.php file, but what to add? Thanks!
If you're in the Loop: <code> echo get_avatar( get_the_author_meta('ID') ); </code>
I want to display author gravatar on posts. How to do this?
wordpress
I need to be able to get the tax percentage for the cart in wp-ecommerce. I have tried using: $wpsc_cart-> tax_percentage but it does not return a value. Has something changed in the newer versions of wp-ecommerce?
<code> $wpsc_cart-&gt;tax_percentage </code> contains the tax percentage for me using the latest version 3.8.6. make sure you have enabled tax and added a tax rate under settings > store > taxes.
how to get tax percentage in wp-ecommerce
wordpress
I'm using the following code to show the subcategories of a category within my archive.php page: <code> &lt;?php if (is_category()) { $this_category = get_category($cat); if (get_category_children($this_category-&gt;cat_ID) != "") { echo "&lt;div id='catlist'&gt;&lt;ul&gt;"; wp_list_categories('orderby=name&amp;hide_empty=0&amp;title_li=&amp;use_desc_for_title=1&amp;child_of='.$this_category-&gt;cat_ID); echo "&lt;/ul&gt;&lt;/div&gt;"; } }?&gt; </code> The code above returns the name of the category as a link, with the category description as the link title. Can anyone show my how to show the category description within paragraph tags after the category link? Thanks.
<code> wp_list_categories </code> formats the results, instead you want to try <code> get_categories </code> and create your own loop to format the results. I do not know exactly how you want it formated, but this gives you the general idea. <code> &lt;?php if (is_category()) { $this_category = get_category($cat); if (get_category_children($this_category-&gt;cat_ID) != "") { echo '&lt;div id="catlist"&gt;&lt;ul&gt;'; $childcategories = get_categories(array( 'orderyby' =&gt; 'name', 'hide_empty' =&gt; false, 'child_of' =&gt; $this_category-&gt;cat_ID )); foreach($childcategories as $category) { echo '&lt;a href="' . get_category_link( $category-&gt;term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category-&gt;name ) . '" ' . '&gt;' . $category-&gt;name.'&lt;/a&gt;'; echo '&lt;p&gt;'.$category-&gt;description.'&lt;/p&gt;'; } echo '&lt;/ul&gt;&lt;/div&gt;'; } } ?&gt; </code> For more examples and information visit, get_categories
Show Subcategory Description
wordpress
My site works with phrases and texts In one category, the users send statements and debate about it. In another category, are sent statements and debate about them. I would like to show only the title of the post into a certain category, since they are not phrases and content needs, just the title. in another category, the pots are usually shown, with title and content. as might be the code in single.php if you are in category X displays content and title Y if the category content is not displayed, only the title
resolved, link : codex.wordpress.org/Category_Templates
display only the title of the post into a certain category
wordpress
I'm trying to make a table of users by role type. What is the best-practices method of getting the user id? My goal is to print each users first &amp; last names, username and email. What I have now: <code> $get_admins = array( 'blog_id' =&gt; $GLOBALS['blog_id'], 'role' =&gt; 'administrator', ); $blogusers = get_users($get_admins); foreach ($blogusers as $user) { $userid = get_userdata($bloguser-&gt;user_id); $user_info = get_userdata($userid); echo '&lt;tr&gt;'; echo '&lt;td&gt;'. $user_info-&gt;user_firstname .'&lt;/td&gt;'; echo '&lt;td&gt;'. $user_info-&gt;last_name .'&lt;/td&gt;'; echo '&lt;td&gt;'. $user-&gt;user_login .'&lt;/td&gt;'; echo '&lt;td&gt;'. $user-&gt;user_email .'&lt;/td&gt;'; echo '&lt;/tr&gt;'; } </code> note: In my example above getting the user id does not work. Codex reference: get_users()
Your code doesn't work because you're using <code> $bloguser </code> instead of <code> $user </code> . And there's no point in calling get_userdata() since get_users() already returns user objects: <code> foreach ($blogusers as $user) { echo '&lt;tr&gt;'; echo '&lt;td&gt;'. $user-&gt;first_name .'&lt;/td&gt;'; echo '&lt;td&gt;'. $user-&gt;last_name .'&lt;/td&gt;'; echo '&lt;td&gt;'. $user-&gt;user_login .'&lt;/td&gt;'; echo '&lt;td&gt;'. $user-&gt;user_email .'&lt;/td&gt;'; echo '&lt;/tr&gt;'; } </code>
Best way to get user id for get_users function?
wordpress
I've been developing a WordPress plugin for a friend who needs something completely out-of-the-box, at least what WordPress is cornerned. Now, I could use the WordPress plugin repository to host this, but I've already hosted this project on Google Code and was wondering if there was any fancy code which would make WordPress check for updates from that repository. I feel this plugin isn't really for the general WordPress crowd and don't want to clutter the directory. So I was wondering if this was possible. Thanks! Davey
Yes, this is possible take a look at WPML to see how its done, also there is an an entire chapter in stackexchange-url ("Professional WordPress Plugin Development") to show you how its done and here is the code that goes with it
Hosting plugin Google Code with auto update?
wordpress
I'm writing a plugin and having a problem. I have <code> add_action('publish_post', 'sender'); </code> and I want this function to run first before the add_filter function, although it won't. Is there a way to do this? I've tried moving the add_filter below add_action but that doesn't work. Also pasting the add_filter one into the add_action function doesn't work. Thanks for the help. Edit: For example, if this would work it would be great. <code> if (add_action('publish_post', 'sender')) { add_filter('wp_insert_post_data','changePost','99',2); } </code> But it doesn't and somehow still runs the add_filter function first.
It doesn't matter the order in which you call <code> add_action() </code> and <code> add_filter() </code> . What matters is the order in which the corresponding <code> do_action() </code> and <code> apply_filters() </code> are called. So, if <code> apply_filters('wp_insert_post_data') </code> is run before <code> do_action('save_post') </code> , tough luck. You'll have to think of another way to achieve the desired result.
Using add_action before add_filter on a plugin?
wordpress
I frequently need to add several Name-Value pairs to the Custom Fields of a post. At present I add these one by one, by entering the Name and Value and clicking Add Custom Field. I'd like to speed this up by entering several pairs into a single box (textarea, prompt, whatever), and have some JavaScript parse them and add them as though I had entered them manually. (Why JavaScript? Because I don't have access to edit any PHP or install any new plugins. I'm doing this browser-side, with Greasemonkey.) As far as I'm aware, the Add Custom Field button submits the Name-Value pair with AJAX, but I'm not familiar enough with jQuery or WordPress to find the exact code that does this so that I can copy it. Any pointers would be much appreciated. Thanks!
Quick search shows that related part of form is generated by <code> meta_form() </code> function. Start from there I guess. Also note that you will need to retrieve from source and submit nonce that protects that form. I am not sure if submitting single field invalidates the nonce there, but that also might be the case.
How can I duplicate "Add Custom Field" with just JavaScript?
wordpress
Is there any equivalent to functions like <code> plugins_url() </code> and <code> content_url() </code> that give you either the relative paths or the file path. For instance, instead of http://localhost:8888/wordpress-3.2/wp-content I want: /Users/username/Sites/wordpress-3.2/wp-content I know that I can build this path using the <code> ABSPATH </code> constant, but I'm specifically interested in learning if there are built in functions to handle this. In the meantime, I'll probably just write a function to swap the url for the abspath. EDIT: Here's the simple function that I wrote to handle this: <code> function get_file_path($url) { return str_replace(site_url(), ABSPATH, $url); } </code> Seems to do the trick, but I'd much rather use built in functions if available.
There aren't any for plugins, but you can (and should) use WP_CONTENT_DIR, instead of ABSPATH. For themes you have locate_template().
Are there functions for file paths, instead of just urls
wordpress
I'm using Simple Local Avatars for uploading custom user avatars. How can I create a frontend page with the avatar upload function? Below please find the code from Simple Local Avatars plugin: <code> &lt;?php /** * add field to user profiles */ class simple_local_avatars { function simple_local_avatars() { add_filter('get_avatar', array($this, 'get_avatar'), 10, 5); add_action('admin_init', array($this, 'admin_init')); add_action('show_user_profile', array($this, 'edit_user_profile')); add_action('edit_user_profile', array($this, 'edit_user_profile')); add_action('personal_options_update', array($this, 'edit_user_profile_update')); add_action('edit_user_profile_update', array($this, 'edit_user_profile_update')); add_filter('avatar_defaults', array($this, 'avatar_defaults')); } function get_avatar($avatar = '', $id_or_email, $size = '80', $default = '', $alt = false) { if (is_numeric($id_or_email)) $user_id = (int) $id_or_email; elseif (is_string($id_or_email)) { if ($user = get_user_by_email($id_or_email)) $user_id = $user-&gt;ID; } elseif (is_object($id_or_email) &amp;&amp; !empty($id_or_email-&gt;user_id)) $user_id = (int) $id_or_email-&gt;user_id; if (!empty($user_id)) $local_avatars = get_user_meta($user_id, 'simple_local_avatar', true); if (!isset($local_avatars) || empty($local_avatars) || !isset($local_avatars['full'])) { if (!empty($avatar)) return "&lt;img src='http://www.wrongmag.ru/wp-content/themes/wrongmag/scripts/timthumb.php?src=/uploads/default-avatar.png&amp;amp;w={$size}&amp;amp;h={$size}&amp;amp;zc=1' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' /&gt;"; remove_filter('get_avatar', 'get_simple_local_avatar'); $avatar = get_avatar($id_or_email, $size, $default); add_filter('get_avatar', 'get_simple_local_avatar', 10, 5); return $avatar; } if (!is_numeric($size)) $size = '80'; if (empty($alt)) $alt = get_the_author_meta('display_name', $user_id); if (empty($local_avatars[$size])) { $upload_path = wp_upload_dir(); $avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']); $image_sized = image_resize($avatar_full_path, $size, $size, true); if (is_wp_error($image_sized)) $local_avatars[$size] = $local_avatars['full']; else $local_avatars[$size] = str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized); update_user_meta($user_id, 'simple_local_avatar', $local_avatars); } elseif (substr($local_avatars[$size], 0, 4) != 'http') $local_avatars[$size] = site_url($local_avatars[$size]); $author_class = is_author($user_id) ? ' current-author' : ''; $avatar = "&lt;img alt='" . esc_attr($alt) . "' src='" . $local_avatars[$size] . "' class='avatar avatar-{$size}{$author_class} photo' height='{$size}' width='{$size}' /&gt;"; return $avatar; } function admin_init() { load_plugin_textdomain('simple-local-avatars', false, dirname(plugin_basename(__FILE__)) . '/languages/'); register_setting('discussion', 'simple_local_avatars_caps', array($this, 'sanitize_options')); add_settings_field('simple-local-avatars-caps', __('Local Avatar Permissions', 'simple-local-avatars'), array($this, 'avatar_settings_field'), 'discussion', 'avatars'); } function sanitize_options($input) { $new_input['simple_local_avatars_caps'] = empty($input['simple_local_avatars_caps']) ? 0 : 1; return $new_input; } function avatar_settings_field($args) { $options = get_option('simple_local_avatars_caps'); echo '&lt;label for="simple_local_avatars_caps"&gt; &lt;input type="checkbox" name="simple_local_avatars_caps" id="simple_local_avatars_caps" value="1" ' . @checked($options['simple_local_avatars_caps'], 1, false) . ' /&gt; ' . __('Only allow users with file upload capabilities to upload local avatars (Authors and above)', 'simple-local-avatars') . ' &lt;/label&gt;'; } function edit_user_profile($profileuser) { ?&gt; &lt;h3&gt;&lt;?php _e('Avatar', 'simple-local-avatars'); ?&gt;&lt;/h3&gt; &lt;table class="form-table"&gt; &lt;tr&gt; &lt;th&gt;&lt;label for="simple-local-avatar"&gt;&lt;?php _e('Upload Avatar', 'simple-local-avatars'); ?&gt;&lt;/label&gt;&lt;/th&gt; &lt;td style="width: 50px;" valign="top"&gt; &lt;?php echo get_avatar($profileuser-&gt;ID); ?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php $options = get_option('simple_local_avatars_caps'); if (empty($options['simple_local_avatars_caps']) || current_user_can('upload_files')) { do_action('simple_local_avatar_notices'); wp_nonce_field('simple_local_avatar_nonce', '_simple_local_avatar_nonce', false); ?&gt; &lt;input type="file" name="simple-local-avatar" id="simple-local-avatar" /&gt;&lt;br /&gt; &lt;?php if (empty($profileuser-&gt;simple_local_avatar)) echo '&lt;span class="description"&gt;' . __('No local avatar is set. Use the upload field to add a local avatar.', 'simple-local-avatars') . '&lt;/span&gt;'; else echo '&lt;input type="checkbox" name="simple-local-avatar-erase" value="1" /&gt; ' . __('Delete local avatar', 'simple-local-avatars') . '&lt;br /&gt; &lt;span class="description"&gt;' . __('Replace the local avatar by uploading a new avatar, or erase the local avatar (falling back to a gravatar) by checking the delete option.', 'simple-local-avatars') . '&lt;/span&gt;'; } else { if (empty($profileuser-&gt;simple_local_avatar)) echo '&lt;span class="description"&gt;' . __('No local avatar is set. Set up your avatar at Gravatar.com.', 'simple-local-avatars') . '&lt;/span&gt;'; else echo '&lt;span class="description"&gt;' . __('You do not have media management permissions. To change your local avatar, contact the blog administrator.', 'simple-local-avatars') . '&lt;/span&gt;'; } ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;script type="text/javascript"&gt;var form=document.getElementById('your-profile');form.encoding='multipart/form-data';form.setAttribute('enctype','multipart/form-data');&lt;/script&gt; &lt;?php } function edit_user_profile_update($user_id) { if (!wp_verify_nonce($_POST['_simple_local_avatar_nonce'], 'simple_local_avatar_nonce')) return; if (!empty($_FILES['simple-local-avatar']['name'])) { $mimes = array( 'jpg|jpeg|jpe' =&gt; 'image/jpeg', 'gif' =&gt; 'image/gif', 'png' =&gt; 'image/png', 'bmp' =&gt; 'image/bmp', 'tif|tiff' =&gt; 'image/tiff' ); $avatar = wp_handle_upload($_FILES['simple-local-avatar'], array('mimes' =&gt; $mimes, 'test_form' =&gt; false)); if (empty($avatar['file'])) { switch ($avatar['error']) { case 'File type does not meet security guidelines. Try another.': add_action('user_profile_update_errors', create_function('$a', '$a-&gt;add("avatar_error",__("Please upload a valid image file for the avatar.","simple-local-avatars"));')); break; default: add_action('user_profile_update_errors', create_function('$a', '$a-&gt;add("avatar_error","&lt;strong&gt;".__("There was an error uploading the avatar:","simple-local-avatars")."&lt;/strong&gt; ' . esc_attr($avatar['error']) . '");')); } return; } $this-&gt;avatar_delete($user_id); update_user_meta($user_id, 'simple_local_avatar', array('full' =&gt; $avatar['url'])); } elseif (isset($_POST['simple-local-avatar-erase']) &amp;&amp; $_POST['simple-local-avatar-erase'] == 1) $this-&gt;avatar_delete($user_id); } function avatar_defaults($avatar_defaults) { remove_action('get_avatar', array($this, 'get_avatar')); return $avatar_defaults; } function avatar_delete($user_id) { $old_avatars = get_user_meta($user_id, 'simple_local_avatar', true); $upload_path = wp_upload_dir(); if (is_array($old_avatars)) { foreach ($old_avatars as $old_avatar) { $old_avatar_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $old_avatar); @unlink($old_avatar_path); } } delete_user_meta($user_id, 'simple_local_avatar'); } } $simple_local_avatars = new simple_local_avatars; if (!function_exists('get_simple_local_avatar')): function get_simple_local_avatar($id_or_email, $size = '80', $default = '', $alt = false) { global $simple_local_avatars; return $simple_local_avatars-&gt;get_avatar('', $id_or_email, $size, $default, $alt); } endif; register_uninstall_hook(__FILE__, 'simple_local_avatars_uninstall'); function simple_local_avatars_uninstall() { $simple_local_avatars = new simple_local_avatars; $users = get_users_of_blog(); foreach ($users as $user) $simple_local_avatars-&gt;avatar_delete($user-&gt;user_id); delete_option('simple_local_avatars_caps'); } </code> I have tried many variants but all of them failed. Could you please give a hint, what pieces of code I shall copy to my custom frontend template file? Thank you very much.
Sergey, use this in place where you are going to put form to edit avatar: <code> &lt;?php $myAv = new simple_local_avatars(); $myAv-&gt;edit_user_profile($profileuser); ?&gt; </code>
Frontend Simple Local Avatar upload
wordpress
is it possible to sign in with user_email instead of user_login , please ? Thanks.
Here's how we do it: <code> $user = get_user_by('email', $email); if (wp_check_password($password, $user-&gt;user_pass, $user-&gt;ID)) { // Login successfull, redirect if needed wp_set_auth_cookie($user-&gt;ID); } </code> Assuming of course that you got the $email and the $password variables from a POST request or something :)
Is it possible to sign in with user_email in Wordpress?
wordpress
I'm using the following code to display a custom value. The custom value being 'website' <code> &lt;?php $custom_fields = get_post_custom($post_id); //Current post id $my_custom_field = $custom_fields['website']; //key name foreach ( $my_custom_field as $key =&gt; $value ) echo $key . " =&gt; &lt;a href='" . $value . "'&gt;Click Here&lt;/a&gt;&lt;br /&gt;"; ?&gt; </code> However, before the 'Click here' i'd like to include another custom value, thumb. So the output would be: <code> Value of custom field thumb Value of custom field website </code> Thanks.
How about: <code> $thumb = get_post_meta( $post_id, 'thumb', true ); $url = get_post_meta( $post_id, 'website', true); echo "&lt;a href='$url'&gt;&lt;img src='$thumb' /&gt;&lt;/a&gt;"; </code> The <code> get_post_meta() </code> function is ideal when you know ahead-of-time the names of the fields you want to retrieve. Setting the third parameter to <code> true </code> tells it that you want to return a single value, and not an array of values (it's possible to set multiple values using the same meta key, and get an array of values back).
Display two custom values from a post
wordpress
I'm trying to enable the WordPress content editor as a droppable using jQuery UI drag and drop. However, I can't get the drag to drop, or the drop event to fire. Is there something I'm missing? <code> &lt;ul id="keywords"&gt; &lt;li&gt;drag one&lt;/li&gt; &lt;li&gt;drag two&lt;/li&gt; &lt;li&gt;drag three&lt;/li&gt; &lt;/ul&gt; jQuery("#keywords").find("li").each(function(){jQuery(this).draggable( { helper:'clone', start: function(event, ui){ jQuery(this).fadeTo('fast', 0.5);}, stop: function(event, ui) { jQuery(this).fadeTo(0, 1); } }); }); jQuery('#content').droppable( { drop: function(event, ui) { alert('dropped in content'); //DOES NOT FIRE!!! jQuery(this).dropIt(ui.draggable.html()); } }); if(typeof tinyMCE=='object') { alert('tinyMCE is active'); //DOES NOT FIRE!!! jQuery('#editorcontainer').droppable( { drop: function(event, ui) { alert('dropped in tinyMCE editor'); //DOES NOT FIRE!!! //Dynamically add content tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'New content.'); } }); } </code>
In the above example the following line: <code> jQuery(".myDiv").find("li").each(function(){ </code> should be: <code> jQuery(".keywords").find("li").each(function(){ </code> That should enable the list items to be dragged and dropped. To allow the items to be dropped on the TinyMCE textarea the following code works. <code> $('#editorcontainer').droppable({ drop: function(event, ui) { alert('dropped'); //NOW FIRES! //Dynamically add content tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'New content.'); } }); </code>
How to enable the content editor as a droppable target with jQuery-ui?
wordpress
When using wp_mail, is there any way to verify that the email was sent correctly?
As you have probably found, for wp_mail : A true return value does not automatically mean that the user received the email successfully. A possible workaround is to add an email address that you have access to to the recipients list, and if the one email address receives the mail you can be reasonably (although not 100%) certain that the message was sent.
Using wp_mail - verify that email was sent?
wordpress
I'm looking for a way to only show posts results that contain all of the custom fields requested. Not one or the other. I was only able to get results with one array at a time. Any help would be appreciated. <code> $documents = array( 'post_type' =&gt; 'documents', 'meta_query' =&gt; array( array( 'key' =&gt; 'document-type', 'value' =&gt; 'manual', ), array( 'key' =&gt; 'document-status', 'value' =&gt; 'current', ) ) ); query_posts( $documents ); get_template_part( 'loop', 'documents' ); wp_reset_query(); </code> I also tried an SQL Query without any luck. <code> $documents = " SELECT wposts.* FROM $wpdb-&gt;posts wposts JOIN $wpdb-&gt;postmeta document-status ON ( wposts.ID = document-status.post_id AND document-status.meta_key = 'document-status' ) JOIN $wpdb-&gt;postmeta document-type ON ( wposts.ID = document-type.post_id AND document-type.meta_key = 'document-type' ) WHERE document-status.meta_value = 'current' AND document-type.meta_value = 'manual' AND wposts.post_status = 'publish' AND wposts.post_type = 'documents' AND wposts.post_date &lt; NOW() ORDER BY wposts.post_date DESC LIMIT 0 , 4 "; $documents = $wpdb-&gt;get_results($documents, OBJECT); query_posts( $documents ); get_template_part( 'loop', 'documents' ); wp_reset_query(); </code>
<code> meta_query </code> has a <code> relation </code> parameter just like <code> tax_query </code> so: <code> $documents = array( 'post_type' =&gt; 'documents', 'meta_query' =&gt; array( 'relation' =&gt; 'AND', array( 'key' =&gt; 'document-type', 'value' =&gt; 'manual', ), array( 'key' =&gt; 'document-status', 'value' =&gt; 'current', ) ) ); query_posts( $documents ); get_template_part( 'loop', 'documents' ); wp_reset_query(); </code>
Query post types with multiple keys
wordpress
I'm working on a custom data table to display in the WordPress dashboard. The table populates from a database table I built in a plugin. I've been using the provided WordPress Custom List Table example for most of my coding questions in this area, but the example doesn't have anything for handling bulk actions. Here is the link for the documented example: http://wordpress.org/extend/plugins/custom-list-table-example/ For processing the bulk actions, the example only provides this: <code> function process_bulk_action() { //Detect when a bulk action is being triggered... if( 'delete'===$this-&gt;current_action() ) { wp_die('Items deleted!'); } } </code> I want to know how to pull the items selected for the action so I can delete them or edit their database entries accordingly.
Assuming you're using the standard column_cb() function, the list table will pass the IDs of the selected rows in an array in $_GET, labeled as whatever you assigned to 'singular' in the list table's constructor. Here's a typical column_cb(): <code> function column_cb($item){ return sprintf( '&lt;input type="checkbox" name="%1$s[]" value="%2$s" /&gt;', /*$1%s*/ $this-&gt;_args['singular'], //Let's simply repurpose the table's singular label ("video") /*$2%s*/ $item-&gt;id //The value of the checkbox should be the record's id ); } </code> For example, let's say I have a list table that displays videos. The constructor would look like: <code> function __construct(){ global $status, $page; //Set parent defaults parent::__construct( array( 'singular' =&gt; 'video', //singular name of the listed records 'plural' =&gt; 'videos', //plural name of the listed records 'ajax' =&gt; false //does this table support ajax? ) ); } </code> So, if you check three rows in the list table, select "Delete" from the bulk actions list, and hit apply, you could access the selected rows by using $_GET['video']. <code> function process_bulk_action() { //Detect when a bulk action is being triggered... if( 'delete'===$this-&gt;current_action() ) { foreach($_GET['video'] as $video) { //$video will be a string containing the ID of the video //i.e. $video = "123"; //so you can process the id however you need to. delete_this_video($video); } } } </code>
How are bulk actions handled in custom list table classes?
wordpress
The following function works perfectly when logged-in visitors go to http://sitename.com , taking them to the site homepage. When logged-in visitors go to http://www.sitename.com , however, they're incorrectly redirected to http://sitename.com/splashpage . Does anyone know what's causing this? I have tried switching my site settings to use http://www.sitename.com as the WordPress and Site Address URLs, but that simply reverses the issue so it incorrectly redirects when a logged-in user goes to http://sitename.com . <code> // REDIRECT USERS TO SPLASH PAGE IF THEY'RE NOT LOGGED IN add_action ('template_redirect','mkm_restrict_access',1); function mkm_restrict_access() { $url = site_url('/splashpage/'); if (is_page('splashpage') || is_page('login')) { //do nothing } elseif (!is_user_logged_in()) { wp_redirect( $url ); exit; } } </code> Thank you for your help!
Figured it out, though this is the lamest solution ever: I hooked into wp_footer instead of template_redirect. If anyone has a better solution or place to hook in I'd love to hear about it - thanks! EDIT: That wasn't the fix I thought it was. Turned out I was writing the function poorly, and did need to be using template_redirect. See stackexchange-url ("Cannot get redirect working")
wp_redirect not working when going to www version of site
wordpress
I have a client who's site is built using WordPress. The account is using cPanel with webmail accessible at domain.com/webmail. They have 2 email accounts setup ([email protected] and [email protected]). I would love to be able have them access their webmail by logging into their WordPress site and clicking a menu link saying "Access Webmail" and then either pulling the cPanel webmail into an iframe, or some other method, but would ideally like to either sync or pre-populate the webmail info with their WordPress user info (email addy and password). I have searched for a plugin but haven't found anything. Anybody ever done this? Where would I begin? Thanks!
You would have to write this from scratch but it is entirely possible. cPanel webmail is already configured to work with Horde, Roundcube and SquirrelMail which are all open source and very well documented. The main issue that wouldn't make it seamless is that cPanel uses exim4 as an email server and there would be no way to map the WordPress username and password info with the server authentication. This means they would have to be logged into both WP and cPanel. Roundcube is better documented than SquirrelMail and you could probably work with the api and include the necessary code using includes from WordPress. If you wanted to sync the user info you would need to install dovecot and postfix which can use virtual users that are mapped to mailboxes via a mysql database. You could just change the mappings to the WordPress database. I'm writing a plugin for a client that will administer the email server from the WordPress dashboard but email functions aren't needed. I built the email servers from scratch using this excellent guide . My plugin will create email accounts for WordPress users and also allow the admin to manage email accounts for the entire domain including non WordPress users. It will also allow the admin to create additional virtual aliases (forwarding email addresses).
Sync User to cPanel webmail?
wordpress
This might be a total dummy question, but I have no idea where to enter the forum description with bbpress. I see it on plenty of other bbPress-powered forums, and the plugin is inserting <code> &lt;div class="bbp-forum-description"&gt;&lt;/div&gt; </code> into my table of entries, but when I create or edit a forum, I don't see a field to enter this information. Is this normal or is something strange going on with my bbPress forum?
Are you using the standalone, or the plugin? I'm not sure if there is a difference honestly, I've never touched the standalone. Anyway, I have the plugin going From my admin panel I have the option of adding/editing forums/topics/replies Clicking on Add New for forum brings up a standard WP post screen The title is the name of the forum, the post body area is the description. Is that not what you get?
bbPress plugin - How do I add a forum description?
wordpress