question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
<code> if ( function_exists('register_sidebar') ) register_sidebar(array( "name" =&gt; "Top Widget Area", "id" =&gt; "topWidgetArea-$i", )); </code> I just create a new sidebar with this. I'm displaying this sidebar in my <code> header.php </code> like this: <code> &lt;?php dynamic_sidebar( "Top Widget Area" ); ?&gt; <...
Changing widget's ID from <code> topWidgetArea </code> to <code> top-widget-area </code> solved my problem. Widget ID must have hypen. I tried a lots of variations for ID (like <code> testtesttest </code> , <code> asdasdasd </code> , <code> widgetareaaa </code> ) . I'm not sure, why .
Widget items disappearing
wordpress
I am debugging my theme using Debug Bar plugin, which is showing me this error (among a few others): Notice: <code> add_custom_image_header </code> is deprecated since version 3.4! Use <code> add_theme_support( 'custom-header', $args ) </code> instead. Okay, clearly, it says I need to use this instead of this . The que...
Please read Updating Custom Backgrounds and Custom Headers for WordPress 3.4 . Custom Headers Old method: // Define default header image constant define( 'HEADER_IMAGE', get_template_directory_uri() . '/images/headers/default.jpg' ); // Define header image width constant define( 'HEADER_IMAGE_WIDTH', 1000 ); // Define ...
Use 'add_theme_support' instead of 'add_custom_image_header' In WordPress 3.4
wordpress
I want to change the code below to allow for multiple checkboxes to be selected. It currently saves and updates only one selction. And to update the option again, I have to "uncheck" the previous selection then make another single selection for it to save. <code> case 'tax_select': $terms = get_terms( $field['id'], 'ge...
After days and days of frustration, I'm proudly answering my own question. The original code was not displaying multiple checkboxes because I was using the conditional <code> !strcmp( $term-&gt;slug, $selected[0]-&gt;slug ) </code> to render my "checked" options. Somehow it only returned 1 "checked" value at best. The ...
Changing checkbox array from single to multiple select
wordpress
i'm working on updating a theme and previously it had used a lot of php CONSTANTS to set up some options as true or false. we're going to be updating these "decisions" to use add_theme_support() instead. is it appropriate to use the _deprecated_argument() function to tell child themers that these constants are deprecat...
Unfortunately there is no way to trigger WP deprecation warning for PHP constants. What I can suggest - to use your constants and "theme support" options together. First for backward compatibility, second for customization facilities. Your theme will have to rely on "theme support" options only, and keep constants only...
_deprecated_argument for constants
wordpress
I have a problem with set_post_thumbnail_size() function, which seems it doesn't work. Or at least it doesn't work correctly. I have set a thumbnail size 75x75px in WordPress settings under the media section and have also set another thumbnail size in the functions.php using: <code> set_post_thumbnail_size(80, 80, true...
They work independently of eachother. You need to call the one you created in the functions.php. So in your functions.php you would have something like: <code> if (function_exists('add_theme_support')) { add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 75, 75, true ); // default thumbnail size add_image...
Can't get image size set with set_post_thumbnail_size() function
wordpress
I have come across quite an odd problem when using the <code> update_option </code> function, and I am sure that I've tried everything I can think of to get it working, but unfortunately it isn't. I'm using AJAX to submit a form (using the popular method described here ) in the backend, on a custom options page. Everyt...
Turns out, my question didn't even have to do with AJAX, it had to do with the function used to validate the settings that was supplied with <code> register_setting </code> . The problem with it was that it wasn't going deep enough into the array to even save the values. I needed to modify it to look like so: <code> pu...
update_option is not saving an array, but saving the string 'Array'
wordpress
My head hurts... Here is what I have: Custom post type: Our People, slug => our-people Taxonomy: Job Title, slug => job-title I have an archive page for the Our People CPT at domain.com/our-people . I can easily have archive pages for the Job Title taxonomy terms at domain.com/job-title/{term} But I would like to have ...
You have two avenues: Hardcode rewrite rules for those specific URLs Abandon your quest and design a new URL structure What your asking for cannot be automated efficiently because it would mean 2 rewrite rules that are the same, but are mapped on to different things. The result being that either the post type slug woul...
Taxonomy archive with same slug as custom post type?
wordpress
I am trying to achieve the following look in the time format: I have for now several issues, First is that the month and year are not displayed at all, I use <code> &lt;?php the_date('D'); ?&gt; </code> <code> &lt;?php the_date('M'); ?&gt; </code> <code> &lt;?php the_date('Y'); ?&gt; </code> for start and only the day ...
I believe all the info you need is in the PHP Manual for Date/Time . Also, it is recommended that you use <code> get_the_date(); </code> instead of <code> the_date(); </code> Get them month in 3 cap letters? <code> M </code> is the right format character that outputs a short textual representation of a month (3 chars)....
Separately formatting date elements
wordpress
I am developing a theme which will have 2 configuration options for the slideshow in the header; a full width version and a half width version. The theme is also responsive and so I am trying to optimize it as much as possible from a speed point of view. I am trying to decide which approach is best. Use <code> add_imag...
The best approach is to serve the smaller image sizes, that is what matters to the end user. If you do the math on something like 5 slider images (large ones) you will see a pretty significant difference. Image sizes are in most cases the largest request. The downside is simply having more storage on your server, but t...
Custom image size vs CSS sizing
wordpress
I'm trying to do a template redirect in my wordpress but with partial success <code> function ahaali_qa_theme_redirect(){ global $wp; $plugindir = dirname(__FILE__); if(is_archive()){ $tname = 'archive-question.php'; if(file_exists(TEMPLATEPATH.'/'.$tname)){ $returntemplate = TEMPLATEPATH.'/'.$tname; }else{ $returntemp...
this is just a simple php syntax issue- anything that meets the conditions <code> is_archive() &amp;&amp; is_tax('question_category') </code> will also return true for the first <code> if(is_archive()) </code> , so you're code is never reaching that test.
Template redirect is_tax() not working
wordpress
I have spent hours today on a maddening issue I was having with displaying a custom post type. Everything displayed beautifully, except the pagination simply would not work properly. I have a page-template setup to display a "page of posts" (see Codex: Page of Posts ) for a custom post type ('news'). I keep getting a 4...
I figured this problem out literally seconds before I posted the question, so I thought I would go ahead and post the answer here. I've noticed there is not a lot of consolidated help for this problem out there. This will help you if your "Older Posts" or "Newer Posts" links give you a 404 error when trying to display ...
Custom Post Types, Page Templates and Pagination. Why do I get a 404 Error?
wordpress
This seems like a very simple question. I'm looking for something like sub-page.php or page-child.php where I can do some different things on the child pages of my theme. They are different enough in design and content that I'm having to use a lot of php or the CSS .page-child class to do all the dirty work. I'm lookin...
There is no specifica template for child pages, but you can do this pretty easily with the get_template_part() function. First create a file called "content-child.php". Second create a file called "content.php". Next, inside of page.php, place this: <code> if( $post-&gt;post_parent !== 0 ) { get_template_part('content'...
Is there a default template file for child pages / subpages?
wordpress
How do I avoid ID conflicts if I use the same menu TWICE on one page. FIRST <code> wp_nav_menu( array( 'sort_column' =&gt; 'menu_order', 'theme_location'=&gt;'menu', 'menu_class'=&gt;'menu', 'menu_id'=&gt;'menu' ) ); </code> SECOND: <code> wp_nav_menu( array( 'sort_column' =&gt; 'menu_order', 'theme_location'=&gt;'menu...
The solution is not to call the same <code> 'theme_location' </code> more than once. Theme location is intended to represent an explicit location within the template . Just register a separate <code> 'theme_location' </code> for each separate location within the template that you want to display a nav menu. Consider yo...
How to avoid wp_nav_menu() ID conflict?
wordpress
I'm trying to change a post's parent via the wp_insert_post_data filter but I'm not having any luck. In the example below, I'm replacing any "parent" references with the id I want to set. <code> function my_insert_post_data($data, $postarr){ $data["post_parent"] = 123; $postarr["parent_id"] = 123; $postarr["post_parent...
In order to make it working you need to return updated data: <code> function my_insert_post_data($data, $postarr){ $data["post_parent"] = 123; $postarr["parent_id"] = 123; $postarr["post_parent"] = 123; error_log(print_r($data,true)); error_log(print_r($postarr,true)); return $data; } add_filter( 'wp_insert_post_data' ...
changing parent_id on post
wordpress
I'm using <code> file_get_contents </code> in a theme development (in a widget of the theme). However the theme check plugin gives me following warning: <code> WARNING: file_get_contents was found in the file file.php possible file operations. Line 49: $data = file_get_contents ( 'http://example.com'); Line 62: $count=...
<code> Line 49: $data = file_get_contents ( 'http://example.com'); </code> Don't use <code> file_get_contents </code> to download web page. WordPress has HTTP API for such needs. In your case, I would suggest you to use <code> wp_remote_get( 'http://example.com' ); </code> function instead of <code> file_get_contents <...
file_get_contents Not allowed in Themes?
wordpress
Where should a plugin cache its re-usable results? I have read the code of several well-used Wordpress plugins, and it seems that the answer is not consistent. I have written several plugins myself, and I store things in a cache directory. But I just picked the location of the directory out of a hat, and my code create...
I find that relying on the filesystem to cache results is easy for maintenance, diagnostics, and performance. Please note that this might be true in some (maybe even most) circumstances, but not all of them. If your code is meant for anything beyond personal usage you don't know with which file system and hardware will...
Where should a plugin or widget cache its results?
wordpress
Very simple, where would I hook/filter to alter the users selection of terms when they save a post (Update or Add)? I need to hook in all instances; such as when saving a post via AJAX, saving when JavaScript is disabled and a normal POST is done and when posts are saved via quick edit.
It is always <code> 'save_post' </code> (or <code> 'wp_insert_post' </code> immediately after this). In <code> $_POST['tax_input'] </code> you will find all the terms for all taxonomies associated with the current post. Example: <code> 'tax_input' =&gt; array ( 'location' =&gt; array ( 0 =&gt; '0', ), ), </code> To cha...
What hooks/filters are there to alter selected terms on post save?
wordpress
I'm creating a plugin that will store some simple layouts to be used in shortcodes. The shortcode usage will be similar to <code> [shortcode layout="name"] </code> With this mind I'll need to store each layout in the array as a key/value setup Key = layout name Value = layout markup I'd like to store these in settings ...
Since the layout names are dynamic, perhaps it's better to store them in a numerically indexed nested array? Something like: <code> wpv_settings[layouts][0][name] = $key wpv_settings[layouts][0][markup] = $value wpv_settings[layouts][1][name] = $key wpv_settings[layouts][1][markup] = $value </code> ...etc?
Storage of array in settings
wordpress
Currently I am making a custom design for a site. The problem I'm seeing in Wordpress is about almost all data pulled out from the database. While in certain pages - like front-page.php - it only needs, for example, title, category, two metas and the excerpt, WP gets everything. Hell, the post content is only visible i...
You can filter <code> 'posts_fields' </code> , check if it is the main query and limit the queried fields to … whatever you need. See <code> WP_Query::get_posts() </code> in <code> /wp-includes/query.php </code> for details and side effects. For debugging the queries I recommend the plugin Debug Bar . If you add … <cod...
Disable (or limit) queries when certain content (or data) is not needed (or showed)
wordpress
I have been customising the <code> admin bar </code> in version 3.3 to only have certain custom links with the following added to <code> functions.php </code> : <code> function mytheme_admin_bar_render() { global $wp_admin_bar; $wp_admin_bar-&gt;remove_menu('site-name'); $wp_admin_bar-&gt;remove_menu('new-content'); $w...
EDIT: This is obviously not a good idea if you want to be able to update - see comments below As this site explains , you need to replace <code> &lt;?php printf(__(‘Howdy, %2$s!’), ‘profile.php’, $user_identity) ?&gt; </code> in the wordpress admin with in your case the word 'logout.' Then make the url be <code> echo w...
Make 'Howdy, [name]' function as log out button
wordpress
I'm building a plugin that heavily modifies the commenting section of a blog page. It think that I cannot do this in a way that works with all themes — some CSS has to be tweaked, depending on the particular theme in use. I'd guess that in the future, the plugin will also store some data in the database. So I suppose i...
There is no way to bind it to a specific theme unless you contact theme authors and they link back to you at some point (on theme activation with yellow message on the top or in their admin menu etc). As you suggested yourself, a plugin is supposed to work with any theme. Theme and plugin markets could handle this by i...
Per theme plugins?
wordpress
I was wondering if all wordpress theme have a similar class name for the content.. For example I know the class for post/content in the twenty ten and twenty eleven is <code> .entry-content </code> if not then how would I go about referring contents for all theme using jQuery? e.g $j('.entry-content').css('color','red'...
There is no mandatory class name for posts. Many themes use the <code> post_class() </code> if that is needed but you cannot rely on it. To change the output of <code> the_content() </code> add a 'the_content' </code> .
Do all wordpress themes a similar class name for content?
wordpress
I think thats a quick one: I've got: Custom post type: Food Custom taxonomy (Registered to Food): Fruits Terms in Fruits : Apple , Orange , Cherry If I type in example.com/food?fruits=Apple,Cherry , I get all posts in Fruits with the terms Apple and Cherry , thats great! But I would like to type in example.com/food/fru...
You have to build up the link structure by using filters <code> post_link </code> and <code> post_type_link </code> : <code> add_filter('post_link', 'territorio_permalink', 10, 3); add_filter('post_type_link', 'territorio_permalink', 10, 3); function territorio_permalink($permalink, $post_id, $leavename) { if (strpos($...
Permalink rewrite with custom post type and custom taxonomy
wordpress
I've been playing around with custom post types and taxonomies and banging my head off walls on numerous occasions now - I believe I've read every forum on the internet on how to solve various issues and I'm close with no cigar. I've reset permalinks, added flush_rewrite_rules(); and all the rest I can get the taxonomy...
Well a few weeks on and my answer does seem to work - its interesting hearing people talk of using filters - as far as I am aware they are not necessary. Whether <code> /%product_cat% </code> has any effect I am not sure so for my solution I'm leaving it out: Product_Cat taxonomy should be: <code> 'rewrite' =&gt; array...
either single-{custom}.php 404's OR /taxonomy/ 404's - custom post type and taxonomy permalinks
wordpress
Here are the args for my query : <code> $args = array( 'post_type' =&gt; 'news', 'meta_query' =&gt; array( array( 'key' =&gt; 'topics', 'value' =&gt; 'sports', ) ) ); </code> This works when <code> topics </code> is a string, but not when it is an array. I'd like this query to work when <code> topics </code> is for exa...
Feeding the query an array of possible values If the value in the database is a string and you want to feed the query several values: <code> $args = array( 'post_type' =&gt; 'news', 'meta_query' =&gt; array( array( 'key' =&gt; 'topics', 'value' =&gt; array ( 'sports', 'nonprofit', 'community' ), 'compare' =&gt; 'IN' ) ...
How can I create a meta_query with an array as meta_field?
wordpress
I'm trying to exclude posts from a certain category from being displayed on my home.php. The code that is in my theme is as follows: <code> query_posts(array('post__not_in' =&gt; $featured_posts_array)); if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php t...
First, don't use <code> query_posts() </code> . Just get rid of the call entirely. It will break things. Second: I tried adding the following before the query_posts ( function but it does nothing. Callbacks and <code> add_action() </code> calls belong in <code> functions.php </code> , not in the template file. If you'v...
How to exclude posts from a category when using this particular format
wordpress
I have no previous experience in developing multisites so be easy on me. I´m familiar with developing and launching single sites though. I´m looking for the smoothest way to build a multisite for my client. It doesn't matter if I build locally or on a live development server. The sites will be basically the same but in...
I always develop the webiste locally on my machine with the setup mydomain.dev and using svn or git to save versions of the code. The next step is to put it on a test domain like stage.mydomain.com and after that mydomain.com I use this to change the url:s in the database: http://interconnectit.com/124/search-and-repla...
Best way to develop multisite and deploy on another server?
wordpress
i have installed wordpress and i i have installed couple of plugins and i have got two themes already came with wordpress. What i am asking about today is : what does the Plugins &amp; Theme string value in database mean ? Example [When plugins are active] , there is a value on table of : <code> a:3:{i:0;s:19:"akismet/...
The value is a serialized php array . Further explanation is not really WordPress specific, but here you go -- the 's' is the length of the string representation of the succeeding array element (the length of the string in quotes). I.E. in <code> a:2:{s:12:"twentyeleven";s:7:"/themes";s:9:"twentyten";s:7:"/themes";} </...
Wordpress : Explain Plugins & Theme string value in database
wordpress
As far as I know the showing and hiding of the admin toolbar on the front-end is a global setting, which applies to any page containing <code> wp_footer() </code> . I want to have more specific control over the visibility admin bar—specifically, to be able to hide it based on a URL query string, such as (e.g., <code> ?...
You should be able to just add the filter inside of a conditional: <code> &lt;?php if ($_GET['hidetoolbar']) { add_filter('show_admin_bar', '__return_false'); } ?&gt; </code> or, since conditionally adding action handlers and filters is sometimes frowned upon, you could add your own function as a filter and then put yo...
Hide admin toolbar based on a query string
wordpress
I run two wordpress mu installs. They are both indentical in terms of plugins, themes and network-wide settings. The reason I run two is because they have different root-domains and different superadmins. Is it possible to simplify this setup somehow?
To a certain extent, yes. Take a look at the WP Multi Network plugin. It allows you to have multiple, separate MU networks running off the same installation - same core, same plugins, same themes, same database.
Two wordpress mu installs, same settings/plugins/themes?
wordpress
I'm trying to determine if the REGEX I'm using is incorrect -- or if I'm missing something basic here. The following: <code> add_filter('the_content','wpdu_image_replace'); function wpdu_image_replace($content) { global $post; preg_replace( '/&lt;img.*src="(.*?)".*?&gt;/', '&lt;a href="\1"&gt;Image file&lt;/a&gt;', $po...
You use <code> preg_replace </code> function incorrectly. This function returns replaced content: <code> add_filter( 'the_content', 'wpdu_image_replace' ); function wpdu_image_replace( $content ) { return preg_replace( '/&lt;img.*?src="(.*?)".*?&gt;/', '&lt;a href="$1"&gt;Image file&lt;/a&gt;', $content ); } </code> Al...
post-> post_content filter
wordpress
I'm looking to make the "Alternative Text" field required in the Media Library, just like the "Title" field above it. Screenshot:
I've managed to make it work of sorts... The requirement is not checked in the Media Library upload <code> /wp-admin/media-new.php </code> , but instead in the Media Upload thickbox iframe <code> /wp-admin/media-upload.php </code> . The following is the code that works in the thickbox and displays an alert box making m...
Making Media Library "Alternative Text" Field Required
wordpress
Is it possible to update Wordpress automatically so that when there's a new version of Wordpress, my installation will update itself automatically without me having to login to admin > update ?
Yes it is. Though perhaps not in the way you might be thinking. If you check out some of the shared hosting sites, many of them have the capability to automatically update your WordPress site. Of course, as Milo has said, it can be rather disastrous too. Especially on a site with lots of plugins installed. So the answe...
Update Wordpress automatically on its own
wordpress
Is there a way for someone to query the wordpress API of a blog in order to get the pingbacks/trackbacks for a post? E.g a blog is hosted on example.com. I want to query example.com's wordpress API to get a list of its posts, and for each post I want to query it, to get a list of the trackbacks. Is that possible?
You may be able to find that information in the blog's feed, i.e. example.com/feed/ I'm unsure if the trackback would be public, you may have to view the Comments section of the WordPress blog.
Getting trackpacks/pingbacks for a post via wordpress?
wordpress
The new "Customize" theme screen is a welcome addition in WordPress 3.4, however, I find it conflicts with my method of loading scripts loaded in the footer: In functions.php <code> if(!is_admin()) { /* GET PUBLIC FUNCTIONS *************************************************************/ require_once(TEMPLATEPATH . '/fun...
Okay, first, let's set things up properly, with a callback hooked into an appropriate action hook : <code> &lt;?php function wpse55227_enqueue_scripts() { // Enqueue code goes here } add_action( 'wp_head', 'wpse55227_enqueue_scripts' ); ?&gt; </code> We'll put all of our code in to this callback. The next step is to ad...
How to execute conditional script when on new customize.php (Theme Customize) screen
wordpress
I have an archive page ordered by a numeric value in a custom field. This returns the ordered posts correctly, but does not display posts that don't have a custom field. <code> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts("paged=$paged&amp;cat=7&amp;posts_per_page=24&amp;meta_key=custom_o...
When you specify a meta_key, <code> query_posts() </code> does an INNER JOIN between the wp_posts and wp_postmeta table. That means that any posts that don't have any meta value for the key you specified won't ever be returned in that query. In order to do what you need, you should use the same query you posted in your...
Order posts by custom field and if custom field is empty return remaining posts
wordpress
I'm getting a lot of spam on my Wordpress blog. I'd like to cut down on the amount of comments I have to moderate. I'm looking for a plugin that does something like this: automatically marks comments as spam, and allows me to say "yes, this is spam". Once I've marked the comment as spam, block the user's IP address for...
Here's what I ended up doing. Since I received thousands of spam comments a week, I began to mark the spam comments as spam. Then, I installed WP-Ban , a simple little plugin that allows you to block IP addresses. Then, I used a simple MYSQL code block to show me all the duplicate IP addresses that were marked as spam:...
Is there a spam comment blocker that blocks IP addresses for a limited amount of time?
wordpress
Can I use WordPress for Urdu Language? I want entire site to be toggled-translated in Urdu Language with one click... Is it possible to do it with some plugin or do i have to write manual codes for every component? Thanks
WordPress is community translated. For a good number of languages, the translation is relatively complete and follows high quality standards. The codex page on WordPress in your language reports: WordPress in Urdu - اردو is ongoing, but slow. Need more contributors. So in essence: No, WP is not entirely translated to U...
WordPress For Urdu Language
wordpress
I'm using Auto Featured Image plugin to generate thumbnails for my posts. After upgrading to WP 3.4 all the posts that had videos and thumbnails generated from youtube disappeared. I found another plugin called Video Thumbnails which created the thumbnails for all video posts but now the thumbnails are not showing on t...
There seems to be a solution there , though it's not perfect -it worked perfectly on one of my two sites and almost perfectly on the other...-
Thumbnails from video posts not working after upgrading to WP 3.4
wordpress
I used the following to enqueue jquery plugins: <code> &lt;?php function my_scripts_method() { wp_enqueue_script( 'custom functions', get_template_directory_uri() . '/js/main.js', array('jquery'), '1', true ); wp_enqueue_script( 'dotdotdot &amp; lightbox', get_template_directory_uri() . '/js/plugins.js', array('jquery'...
Use closure for your scripts: <code> (function($){ $(document).ready(function() { // do something... }); })(jQuery); </code> It is safe way to use jQuery.
Why $ for jquery doesn't work?
wordpress
I'm making a mobile site and I'm using the main computers IP adress to connect to it from the iphone <code> 10.0.0.1/wp </code> With normal sites it works fine, but the WP site I get is stripped from CSS, JS, and images, only plain text. on the mac and the iphone-simulator it works fine. Is it something known and confi...
It may be a conflict between the internal option <code> 'home' </code> or <code> 'siteurl' </code> and the access per pure IP address. WordPress doesn’t use just any server name, there is some redundancy which may get in your way here. You can try to resolve that by two constants defined in your <code> wp-config.php </...
Can't access WP site over WiFi network
wordpress
So in english we don't have gendered nouns. It is always "a table" or "a desk" with no need to worry about it being "une table" or "un tableau" (french). So my question is that when working on the french .mo file, how does one translate a string such as : You can include a %s in a childtheme since the "a" depends on wh...
This is not a problem if every string gets its own template for translation. If you use the string <code> You can include a %s in a childtheme. </code> more than one time for different nouns it is not translatable. An example, taken from a recent article: <code> New %s </code> is in German (yes, we have gendered nouns ...
Translate a string to a language with masculin/feminine nouns
wordpress
question WHEN does the integer output of get_user_count() turns into an array ? background The function get_user_count() in ms-functions.php returns an integer (it calls get_site_option('user_count') The function wp_version_check() in update.php stores this integer in $user_count on line 55 Directly after that on line ...
Via: http://lists.automattic.com/pipermail/wp-hackers/2012-June/043295.html http://wordpress.org/support/topic/illegal-string-offset-total_users?replies=14#post-2893756 https://core.trac.wordpress.org/ticket/20966 I find: Normally it would return an array from the cache Meaning the return value of get_user_count() is d...
when does output of get_user_count turns into an array?
wordpress
We rented a SEO specialist for our site, and he says that we have to do some changes in site structure before he starts his work. The first is, that now most pages have 301 redirection. For example: <code> mysite.com/2010/12/02/postname/?p=5500 </code> is redirected to <code> mysite.com/2010/12/02/postname/ </code> som...
Yup, that is very normal. If you don't want WP to redirect anything. Simply remove the action by adding this code into your working template functions.php file. <code> remove_action( 'template_redirect', 'redirect_canonical' ); </code> That will deactivate the redirections, all of them.
Does WP always makes 301 redirection?
wordpress
I upgraded to WordPress 3.4 and am having an issues with showing a different amount of post on the first page versus the rest. The first page is still showing 5 posts but when I go to /page/2/ I'm getting a 404 error. I have pagination on the custom post type pages and author pages and it works just fine. This is only ...
It stopped to work with WP 3.4 because there was fixes to handle_404(), and You are using wrong way on homepage... instead of creating new query, modify main query. Changeset: http://core.trac.wordpress.org/changeset/19892 Sample code: <code> function my_query_for_homepage( $query ) { if( $query-&gt;is_main_query() &am...
Issue with front page navigation after upgrading to 3.4
wordpress
I want to hide or show an HTML widget I built depending on whether someone adds custom fields to a page via WP Admin. Is this possible? I'd like to do this in my HTML widget template (tips.php): check if there is a value for each of the custom fields in this template. If there isn't, hide this html from view. Otherwise...
You can call <code> get_post_meta </code> inside of a conditional statement and display data depending on the field value (empty or set), check the sample loop in the Codex
Is it possible to use get_post_meta() to control HTML?
wordpress
How can I go about getting the previous and next posts from outside the loop? Everything I try to do aside from the custom SELECT query (using <code> get_posts </code> or <code> WP_Query </code> ) breaks stuff further down the page. I currently have a recursive function which will hopefully find the first "previous" po...
Take a look at <code> get_previous_post() </code> and <code> get_next_post() </code> and you'll see they both use the <code> get_adjacent_post() </code> to find the previous or next post. Let's say you want to fetch the ID of the immediately previous post based on the current post's ID. This is what you'd do: <code> ge...
Get Previous & Next posts by Post ID
wordpress
I want to make a theme with an about page and a contact form, Should I make a custom page meant specifically for it? (the blog is ment for mobile and I'm not looking for most flexibility, the page can be all hard coded but the text) And how would such page be created from the WP-Admin?
If you're building a custom theme, I'd recommend creating custom page templates - one each for an About and a Contact page. This gives your end users some flexibility. They can define their own page and select your template - so "About" could be used for "About," "About Me," "Our Story," etc. No need to know which page...
What page should I use for a contact form?
wordpress
By default an author can select from Paragraph, Address, Preformatted, Heading 1, etc.. As an example I'd like the author to have the ability to visually wrap selected text in a tag, without ever seeing the tag. Is TinyMCE Advanced the only/best way to go?
Assuming that you are using WP 3.2+ and an up-to-date theme, the editor-style.css file should contain the styles for the editor. If you don't have one, just create it in the same place as style.css The style appear in the Styles dropdown not the paragraph type dropdown that you referenced in the question. This does ind...
How can I add custom text styles to the visual text editor?
wordpress
The scenario is this: I have a CPT called Job. I've set custom row actions for this CPT, and most of them are linked to external or custom settings pages. They work fine. Now I've set a new row action, called as 'mark-special', and I've set the href for the link as the same posts list page with my own params as: <code>...
Found the issue. I have used <code> action </code> as a url arg, which WP uses for all its actions such as <code> approve_comment </code> , <code> trash_post </code> etc. Changed it to a custom word and my code worked like a charm!
Custom row action on custom posts list page causes a wp_die?
wordpress
I am using word press theme option panel and using those in my header.php without any issues, code as follows... <code> &lt;?php // loading theme options. used in header.php global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'...
If you are using some custom global theme options, I’d set them in <code> functions.php </code> . Then you access them from any template if you declare them <code> global </code> first. <code> // functions.php &lt;?php $aagt_fb_url = 'foo'; </code> - <code> // template file like header.php, index.php, etc. &lt;?php glo...
wordpress theme option in other templates
wordpress
Right now I have a p element in header.php containing the address and phone number my client wishes to use for contact info. How can I set this up so that it is editable through the WP admin area so that my client can easily change this in the future?
Store it in your theme options. Read the series of articles called The Complete Guide To The WordPress Settings API . Spare no effort to read it, especially 4th article about Theme Options .
How should I store global information such as a phone number so that it is editable through the CMS?
wordpress
I have a WordPress plugin, and I must load scripts from my plugin to the front of the site. <code> class My_Plugin { function __construct() { add_action('admin_menu', array(&amp;$this, 'add_submenu')); add_action('admin_init', array(&amp;$this, 'admin_init')) } function load_my_scripts(){ wp_enqueue_script('script', 'j...
Use <code> wp_enqueue_scripts </code> and <code> admin_enqueue_scripts </code> actions to enqueue your scripts: <code> // for front end add_action('wp_enqueue_scripts', array(&amp;$this, 'load_my_scripts')); // for back end add_action('admin_enqueue_scripts', array(&amp;$this, 'load_my_scripts')); </code> Also pay atte...
Add script into front from my plugin
wordpress
this is really a two part question, neither of which I can find the direct answer to. (1) What's the correct way to link assets like buttons or include files like JS? Currently, the src attr for things like this is set to: <code> src="&lt;?php bloginfo('template_url'); ?&gt;/path/to/my/file.xxx" </code> Is that correct...
For general links use home_url() . <code> &lt;a href="&lt;?php echo esc_url( home_url( '/path/to/link' ) );?&gt;"&gt;Anchor&lt;/a&gt; </code> To link to theme assets like images etc use get_stylesheet_directory_uri() . <code> &lt;img src="&lt;?php echo get_stylesheet_directory_uri(); ?&gt;/images/your_image.png" /&gt; ...
What is the right way to code links for Wordpress pages?
wordpress
I am working on a theme at the moment and I have set up a post template. This post template is linked to some custom post types. When I query_posts for my post type on the actual post template itself it makes the content disappear for some reason? Is there something I am missing here? Thanks, Mark My loop is as follows...
use <code> wp_reset_query </code> after your loop to restore the global post data for the main loop.
Why is querying posts messing up my pages?
wordpress
Refering to stackexchange-url ("Post status") because it's not allowed to do a question on a answer ?! Original post is from Bubka Gob and the answer came from Chris O . I have add their code to functions.php: add_action('post_submitbox_misc_actions', 'send_for_correction_button'); function send_for_correction_button()...
That code is part of something bigger, as there are many places where the custom <code> post_status </code> needs to be inserted. There are two interesting discussions here at WPSE and both point to the use of this plugin: Edit Flow . stackexchange-url ("Is it possible to have more &quot;levels&quot; of draft/published...
Changing post status
wordpress
I'm running a multisite network with 200+ themes installed and activated. Is there a way to manipulate the list of available themes in wp-admin so that certain theme does not appear in the list ? I want to do it without editing core files. I know WordPress gets the list of available themes from the function <code> get_...
The following filter works in Multisite in the following screens: <code> /wp-admin/network/themes.php </code> <code> /wp-admin/network/site-themes.php?id=1 </code> (individual sites allowed themes) <code> add_filter( 'all_themes', 'wpse_55081_remove_themes_ms' ); function wpse_55081_remove_themes_ms($themes) { unset($t...
Hide a theme on list of themes in wp-admin without editing core files
wordpress
I have a few scripts which are being enqueued, the problem is that I want to force the order of prominece to which these scripts are loaded. There is one in particular which is loaded from a plugin before the theme ones which requires jquery however the plugin does not require jquery (bad dev on the plugin but I'd rath...
You just need to enqueue your scripts before plugin does it. You can do it by setting priority to 0 for your hook. For example, do the following: <code> add_filter( 'wp_enqueue_scripts', 'wpse8170_enqueue_my_scripts', 0 ); // or if you enqueue your scripts on init action // add_action( 'init', 'wpse8170_enqueue_my_scri...
force enqueue script to be first in order of prominence
wordpress
I have a Wordpress site using custom post types, and I have also got the All In One SEO pack installed. I wondered if anyone knows a hack or a modification I can make to the code which will allow me to stop the pictured area from showing up on certain custom post types? Any help much appreciated.
If you're satisfied with disabling the SEO-Pack on all CPTs, go with brasoflo's answer. Should you want to keep the metabox for some CPTs and disable it only for a select few: <code> function wpse_55088_remove_aiosp() { remove_meta_box( 'aiosp', 'movie', 'advanced' ); } add_action( 'add_meta_boxes', 'wpse_55088_remove_...
Disable All In One SEO Pack for some custom post types
wordpress
I would like to get all the comments for a group of post (not only one post. I tried <code> $comment_args = array('number' =&gt; '14', 'post_id' =&gt; '10,20,30,40' ); $comments = get_comments($comment_args); foreach($comments as $comment) ... </code> But does not work. Any ideas?
The <code> 'post_id' </code> is converted to a positive integer in <code> WP_Comment_Query </code> , so you cannot successful pass anything else to <code> get_comments() </code> . You have to filter <code> 'comments_clauses' </code> . Here you can change the <code> WHERE </code> clause to use <code> comment_post_ID IN ...
Get comments for more than one post
wordpress
I have two custom post types Hotels Things to do And I have two taxonomies Activities Regions So when a user sees a Hotel (custom post): the user can then see the region it's in what activities they can do. And viceversa as well When the user sees Things To Do , he can see in which Region it is and what Hotels have the...
I prefer set different taxonomies with distinct slug for them, I'm dealing with a project alike yours: Hotels (taxonomy is continent-hotels ) values: Europe, Asia etc Places (taxonomy is continent-places ) values: Europe, Asia etc Even if both itens share same taxonomy and value, is easier to link the content than filt...
Two Custom Post Types, Share Two Taxonomies
wordpress
I'm trying to add an ad banner to my wordpress homepage (in the header) plus a separate ad banner for all other pages (in the header). I did get the banner up for just the homepage but I'm trying to figure the code to complete this issue. <code> &lt;?php if ( is_home() ) { ?&gt;&lt;div id="banner"&gt;my content&lt;/div...
What about <code> &lt;?php if ( is_home() ) { ?&gt;&lt;div id="banner"&gt;my content&lt;/div&gt;&lt;?php } else { ?&gt;&lt;div id="banner"&gt;not-home banner/div&gt;&lt;?php } ?&gt; </code>
Banner in Wordpress
wordpress
I'm building a themes option panel and want users to be able to choose between Next/Previous links or pagination in my archives and homepage. I need help combining the two functions below (pagination and next previous) to create a function which chooses based on the user's selection. I figure the function I add to the ...
A simple if statement should do, so something like this: <code> function my_theme_navigation() { if( get_option( $shortname .'_next_prev_or_paginate' ) == 'Next/Previous Links' ) : // the block for next-prev navigation else : // the code for pagination endif; } </code> I have no way of knowing what the array in your fi...
Allow Users to Choose Pagination or Next/Previous (Combine)
wordpress
I write a lot of content on a daily basis, and I have a lot of menus, submenus etc. I don't want to use the menu gui each time I create a new page/article. Is there any plugin or way of automatically putting the pages into the specified submenus?
I believe this plugin will do what you're looking for: Add Descendants as SubMenu Items I'm not sure if it will handle posts / categories but for pages it's good. Hope this helps, best of luck!
Automatically add a page to menu
wordpress
This is more of an efficiency question as the following code does do what I want. <code> $user_name = get_the_authour; $query = new WP_Query('author_name=JustinH'); $author_post_count = $query-&gt;post_count; if ($author_post_count &gt;= jwh_option('post_count_set') { $post_status = 'publish'; }else{ $post_status = 'pe...
This thread on the wordpress codex shows how you can scope your SQL query: <code> $author_post_count = $wpdb-&gt;get_var("SELECT COUNT(*) FROM $wpdb-&gt;posts WHERE post_author = '" . $$username-&gt;ID . "' AND post_type = 'post' AND post_status = 'publish'"); </code>
Determining Author post count
wordpress
Hi below is a 'case' (in a custom post type) for pulling all categories and displaying them as a drop-down menu. How can I do the same but turn it into a list of checkboxes? <code> //tax_select - this lists all of the categories in a drop-down, we want to change to a checkbox case 'tax_select': echo '&lt;select name="'...
<code> //tax_select - this lists all of the categories in a drop-down, we want to change to a checkbox case 'tax_select': $terms = get_terms( $field['id'], 'get=all' ); $selected = wp_get_object_terms( $post-&gt;ID, $field['id'] ); foreach ( $terms as $term ) { printf( '&lt;input type="checkbox" name="%s[]" value="%s" ...
Setup page template array in a custom post type
wordpress
I have the following structure: Hotels (custom post type) Continents (taxonomy) Working actual links examples leading to single post: hotels/europe/france/a-hotel *hotels/europe/italy/firenze/a-hotel* Problem: getting 404 when trying to access childs and grandchilds listings: hotel/europe - works! hotel/europe/france -...
Solved by adding a filter and building the permalink. FIrt forget the pastebin code, just create a post type a nd the taxos you want, them add the filter: <code> add_filter('post_link', 'territorio_permalink', 10, 3); add_filter('post_type_link', 'territorio_permalink', 10, 3); function territorio_permalink($permalink,...
Child and grandchild taxonomy listings - 404
wordpress
I'm getting products (from a specific category) using a custom <code> query_posts() </code> function. I limited the <code> showposts </code> parameter to 25, so how do I know to activate pagination if there are still products (posts) to load? My <code> query_posts() </code> code looks as follows: <code> $args = array( ...
First of all: do not use <code> query_post </code> ! For more information read: stackexchange-url ("When should you use WP_Query vs query_posts() vs get_posts()?") Use the <code> WP_Query </code> class to fetch your products, also pay attention that the <code> showposts </code> argument is deprecated, use <code> posts_...
Determine if more posts are available than was asked for in `query_posts()`?
wordpress
I'm trying to get the min and max values from a taxonomy, but my code is returning all taxonomies: <code> function get_years ($taxonomies, $args){ $hlterms = get_terms($taxonomies, $args); foreach($hlterms as $term){ $term_taxonomy = $term-&gt;year; $output .= $term-&gt;name; } return $output; } $taxonomies = array ('y...
Not sure but try this: <code> function get_years ($taxonomies, $args){ $output = array(); $hlterms = get_terms($taxonomies, $args); foreach($hlterms as $term){ $term_taxonomy = $term-&gt;year; array_push($output, $term-&gt;name); } return $output; } $taxonomies = array ('year'); $args = array ('hide_empty'=&gt;true); $...
Show min and max taxonomy values
wordpress
I have a blog with all media stored in a folder called upload (organize media was disabled), I've activate it to organize new uploads by date. But how can i organize old files? I want this because i need to migrate the site to a Wordpress MU site, and i need to have files organizated.
Thans but I've found the solution, what it need to do is to edit the site (Network -> Sites -> Edit -> Settings ) and change the following parameters: <code> Uploads Use Yearmonth Folders 0 Upload Path wp-content/blogs.dir/1/uploads Fileupload Url http://www.mydomain.com/myblog/uploads </code>
Organize uploaded media files
wordpress
We've set up drop down lists to allow people to filter posts based on custom post types. In order to populate the drop down list I am using: <code> &lt;?php $terms = get_terms("ratios"); $count = count($terms); if ( $count &gt; 0 ){ foreach ( $terms as $term ) { echo "&lt;option value='" . $term-&gt;slug . "'&gt;" . $t...
<code> get_terms </code> function will return an array of object. Each of them has <code> term_id </code> field which contains id of a term. Just use it instead of slug and you will have what you need: <code> &lt;?php $terms = get_terms("ratios"); if ( $count($terms) &gt; 0 ){ foreach ( $terms as $term ) { echo "&lt;op...
Sort a custom post type array numerically
wordpress
How can I remove this custom post type from being shown in the dashboard for non admin users? <code> /* Add Websites Custom Post Type */ add_action( 'init', 'create_website_type' ); function create_website_type() { register_post_type( 'website', array( 'labels' =&gt; array( 'name' =&gt; __( 'Websites' ), 'singular_name...
<code> register_post_type() </code> accepts a parameter <code> capabilities </code> in its arguments. See <code> get_post_type_capabilities() </code> for possible values. From the comments: By default, seven keys are accepted as part of the capabilities array: <code> edit_post </code> , <code> read_post </code> , and <...
Restrict custom post type to only site administrator role
wordpress
Hello wordpress gurus! I want to be able to set the frontpage via a custom field. So for example, in the new page area in the wordpress admin there is a custom field that displays "Set as frontage", instead of the user going to the Settings > Reading settings and setting the front page there they can do it via the new ...
You can do it by updating 2 options. <code> &lt;?php //This could be page or posts. update_option('show_on_front', '&lt;posts/page&gt;'); //This one sets the page you want on front, won't work if the above option is set to 'posts'. update_option('page_on_front', '&lt;id of the page you want to set as front page&gt;'); ...
Set front page option using custom fields?
wordpress
I am wondering how to achieve something specific. I am not sure if this functionality is already built into Wordpress, or if there is some PHP happening. This is the site I am basing some of my design from: http://www.premiumpixels.com/ As you can see, the images that are on the front page are cropped, yet, when you cl...
This is quite simple to implement, using core <code> post-thumbnails </code> functionality. First, you need to add Theme support for the feature , via <code> functions.php </code> : <code> &lt;?php function wpse54920_setup_theme() { // Support post thumbnails add_theme_support( 'post-thumbnails' ); } add_action( 'after...
Different thumbnail size than actual picture in post
wordpress
I am using wordpress for my new website and i have list of clients(name and their logos). I am confused how to make those editable using wordpress? Html as follows... <code> &lt;ul&gt; &lt;li&gt;&lt;img src="1.jpg" alt="client1"/&gt;Client1&lt;/li&gt; &lt;li&gt;&lt;img src="2.jpg" alt="client2"/&gt;Client2&lt;/li&gt; &...
You'll want to use a custom post type for this. But don't let the terms "custom post type" scare you off. For example, one of my clients needed to present a "line card" displaying their various partners. All they wanted, originally, was the name and logo of their various partners. After I built out the feature, they wa...
clients list using wordpress
wordpress
What is the consensus on how to insert variables in a MySQL query using the <code> $wpdb-&gt;insert </code> syntax: <code> ($table, array($column=&gt;$value),$format) </code> ? I know this hasn't worked: <code> $wpdb-&gt;update('wp_mytable', array('product'=&gt;"$product")); </code> Nor this: <code> $wpdb-&gt;update('w...
To insert a new row : <code> global $wpdb; $wpdb-&gt;insert( 'wp_mytable', array( 'product' =&gt; $product ), array( '%s' ) ); </code> For the sake of completeness, <code> $wpdb-&gt;update </code> is used to update an existing row and requires an additional WHERE clause, as would a "regular" SQL query. For example: <co...
PHP variables in mysql query
wordpress
I have a simple site with a few pages plus a blog . For some reason, the blog posts state comments are closed and I can't figure out why. I want to open the comments on all blog posts (and not offer comments on pages). In the "edit post" screen, the "Comments" section just states "No comments yet." but doesn't offer an...
Have you tried go to "Posts" and checked the box next to the title and in the dropdown "Buld Actions" choose Edit and then apply, Comments and in the dropdown "Allow". And also have added the screen in the post edit area on the tab in the header called "Screen Options" and checked the field called: Discussion? And in s...
Why are my comments closed?
wordpress
I have created a form using Cforms from Delicious . The client asked me for an option to print this form as a pdf. I tried some plugins such as Print Friendly and PDF Button that make it possible to add a pdf or print button, but this button is subsequently added to all pages and most of the time the form does not appe...
With help from a dev at WordPress Questions I got this solved. In <code> wp-content/plugins/cforms/cforms.php </code> we added <code> require_once(dirname(__FILE__) . '/html2pdf/html2pdf.class.php'); </code> which loaded all the necessary data from the folder <code> html2pdf </code> which has all the files based on cod...
Print Cforms form as pdf
wordpress
I am rebuilding a static website for a client using Wordpress on the main domain- eg domain.com. There is also a directory of members website at directory.domain.com which I was hoping to migrate over to the main website- <code> domain.com/directory/ </code> (We want to do this, firstly to keep it on the same domain, b...
Its not good way to edit .htaccess for wordpress url rewriting (only for main urls settings from admin panel) You found your response here : API basic url rewriting or The Rewrite API: Post Types &amp; Taxonomies An example : <code> add_action( 'init', 'rewrite_rule' ); function rewrite_rule() { global $wp,$wp_rewrite;...
How do I add my PHP app to a Wordpress page whilst keeping semantic URLs?
wordpress
I am making a custom theme and I want the main page to be a gallery, not a blog, is it right to change <code> index.php </code> to a gallery page (content wise) or should I use another page?
There are definately a few ways of achieving this functionality. I assume by "main page" you mean the home page... a. Create a new page called "home" b. In your site settings change your homepage to point to the "page" home, rather then grabbing your 10 newest posts. c. Now you have a page hook which you can build a cu...
What is the right way to make custom main page?
wordpress
I am not trying to use $wpdb-> insert, but prepare. Insert method will have one query string and an array which includes # of data which is not defined but will be defined for each query string keyword. For example, "address.insert" query string defines a string of query with 3 variables when it process query such as o...
From the Codex , 2nd parameter for the prepare() method: (int|string|array) The value to substitute into the placeholder. Many values may be passed by simply passing more arguments in a sprintf()-like fashion. Alternatively the second argument can be an array containing the values as in PHP's vsprintf() function. Care ...
Wordpress db prepare
wordpress
<code> $vote_count = $wpdb-&gt;get_var($wpdb-&gt;prepare("SELECT votes FROM wp_mytable WHERE product = %s AND company = %s", $product, $company)); if(is_int($vote_count)){ $html = '&lt;a href="#" class="vote_for_doc"&gt; Vote here&lt;/a&gt; (&lt;span class="vote-count"&gt;' . $vote_count . '&lt;/span&gt; Votes for ' . ...
var_dump($vote_count) should tell you what type $vote_count is. Probably you're getting NULL.
get_var is neither a string, integer, or array ...?
wordpress
I am in the process of moving my blog away from GoDaddy (yey!) to HostGator. I used the migration plugin on GoDaddy tat created the gz archive of the database, and I copied all my files over to the new host. My front page displays fine, but it is everything after this that shows 404 - ie. ~/profile-who-am-i/, and other...
Go to Dashboard > Settings > Permalink Settings. However it's set, change it to something else, one of the other formats. I had an issue moving, same symptom as you described, and this fixed it. You can also see this help guide on Go Daddy for help with this issue. (this edit added by another user. NP, but details almo...
All pages after level 1 showing 404 after WordPress migration plugin - how to fix?
wordpress
I would like to submit a "tabindex" attribute in a navmenu structure. The default options do not allow me to do it.
You could write a stackexchange-url ("custom walker") to change the output of <code> wp_nav_menu() </code> . The walker should extend the function <code> start_el() </code> to add your attributes where you need them. Another option would be a filter on <code> 'walker_nav_menu_start_el' </code> . But be aware that <code...
Add tabindex to navmenu
wordpress
Currently, there is no way to do this in a vanilla Wordpress install. Is there a way to retroactively attach an image from the Library to a post? EDIT: Ah, let me clarify — when editing a post, and clicking the "Insert Media" button, I see no way to add past media. I can insert it into the post, but not add it to the p...
This is not something that is currently supported in WordPress. There's some discussion about it here: http://core.trac.wordpress.org/ticket/6820 One plugin which does enable this functionality is: http://skyphe.org/code/wordpress/file-gallery/ This plugin does a few extra things, but one option it provides is that aft...
How can I attach images to a post from the media library?
wordpress
I'm not sure if this is possible or not, but here is what I'm trying to achieve. I'm using WooCommerce , and I have it setup to prepend a base slug and the product category to my product permalinks. So, my product permalinks look like this: <code> example.com/shop/%product_category%/%product_slug% </code> Now, I want t...
Ok, the solution here turned out to be setting the correct priority on the <code> add_action </code> hook. Since we're all hooking into <code> init </code> to register our post types per the Codex, the priority will determine which <code> register_post_type </code> function gets called first and, by extension, the orde...
Rewrite rules for using the same base slug for multiple content types
wordpress
I need to modify the_post_thumbnail function to run "Lazyload" on it, i think there is two solutions : 1- modify the args to be something like this <code> the_post_thumbnail('product', array('data-original'=&gt;$src, 'src'=&gt;'grey.gif')); </code> (((NOT WORKING!))) 2- get only the image url from the function ... i've...
If you want to apply lazyload to each attachment image, you can just add your hoot to <code> wp_get_attachment_image_attributes </code> filter: <code> add_filter( 'wp_get_attachment_image_attributes', 'wpse8170_add_lazyload_to_attachment_image', 10, 2 ); function wpse8170_add_lazyload_to_attachment_image( $attr, $attac...
the_post_thumbnail with lazyload JQ plugin
wordpress
I noticed on one of my WordPress installs I have two admin authors with the same email address. Both of them have posts attributed to them. They are both for the same person, so I'd like to combine the two accounts into one. How can I do this?
Delete one account. Upon deletion WP will prompt you with a question of whether to delete all posts by said author or attribute them to another user. Simple as that, wanted functionality is provided by the core.
How can I merge two authors?
wordpress
Is there any possibility on Wordpress to get an image from a post gallery? Images are not inserted in the post, are on it's gallery. I'm trying to do a "galleries index" page and instead having the user set a "cover image" I'd like to take any of the attached to the post as part of a gallery. I tried the wp_get_attachm...
You can get the attached media to a post using get_children. IE: get the first attached image for post ID == 14 <code> $args = array( 'post_mime_type' =&gt; 'image', 'numberposts' =&gt; 1, 'post_parent' =&gt; 14, 'post_type' =&gt; 'attachment' ); $first_attached_image = get_children( $args ); </code>
Get image from post's gallery
wordpress
According to the codex ( http://codex.wordpress.org/Function_Reference/term_exists ), term_exists returns some mixed results but not NULL. In my case, I'm getting NULL, what am I doing wrong? In this particular example 'Videos' term does not exist under category. Shouldn't it be returning a false or 0? Why NULL? <code>...
It can return null in some cases if you look at the code: http://core.trac.wordpress.org/browser/tags/3.3.2/wp-includes/taxonomy.php#L1492 The method get_var returns null if no result is found. If you check with "==" and not "===" that should work with false or 0.
term_exists returns NULL
wordpress
I just made my wordpress website live finally and now trying to set up the RSS. I came across a couple tutorials saying that you have to go to www.yoursite.com/feed copy the link and place it into the URL area in your feedburner account. However what happens if nothing shows up when you go to www.yoursite.com/feed ? It...
The <code> /feed </code> slug only works if you've turned on pretty permalinks . From the looks of things, you haven't. Instead, you can use this url: <code> http://www.averylawoffice.ca/?feed=rss2 </code> Once you turn on pretty permalinks, that URL will still work, but the prettyier http://www.averylawoffice.ca/feed ...
Feeds not working on my wordpress site
wordpress
On some of my pages (not posts) in my Wordpress site, I need to include a sidebar that display s information relevant to the main content of the page the user is on. I can choose, using Edit Page in WP Admin, the page template I want to use for my page. This template includes the sidebar. No problems here. My question ...
There are quite a few ways to do this, here are a couple: Use a plugin to control which Widgets display on which Pages/Sections. This is a plugin I've used which works well. It adds a "hide/show on...." checklist to each widget where you can select where the widget will display. Works great, but if you have a site with...
How can I use Page editor for two separate templates?
wordpress
Is there a way to have a custom template php file that is only used for previews instead of it using the single.php file? This way the user knows they are in preview mode?
You could use the conditional is_preview() to add a bit of extra content. For instance, you could put this at the very top of your single.php right after the header is called - or you could put it in your header.php file if you want it shown at the very top of the page: <code> &lt;?php if ( is_preview() ) { ?&gt; &lt;d...
Post/Page Preview Template
wordpress
I'm having a problem with my WordPress installation. I'm trying to move it from one host to another (switching hosting providers for my sites). I was following the instructions given here , and everything went smoothly except for one little thing: I can no longer access the dashboard. Similar to this (unanswered) quest...
I ended up deleting that copy of the installation, and cloning my site using the manageWP plugin instead. That worked just fine.
Moving from one host to another - cannot access the dashboard
wordpress
I'm using <code> $_GET["post_type"] </code> to direct my search to the correct templates and have used the following: <code> &lt;?php $search_refer = $_GET["post_type"]; if ($search_refer == 'news') { load_template(TEMPLATEPATH . '/search-news.php'); } elseif ($search_refer == 'members') { load_template(TEMPLATEPATH . ...
I think you need to check status in your <code> search-news.php </code> template. And if <code> $_GET['status'] </code> is equal to <code> future </code> , create custom loop for it. Your <code> search-news.php </code> could look something like this: <code> if ( $_GET['status'] == 'future' ) : $the_query = new WP_Query...
Redirecting search to specific templates with $_GET["post_type"]
wordpress
Please, someone can help?! I'm fighting with this for weeks and nothing.... I'm quite new in wordpress and php... There is a way to list taxonomy terms based on another taxonomy? OR If is possible to list taxonomies based on post category. BUT, I'm doing this on homepage, not post page... The function above retrieve my...
If you are trying to print children of a category, this should be sufficient: <code> &lt;?php wp_list_categories('orderby=id&amp;show_count=1&amp;use_desc_for_title=0&amp;child_of='.$term_id); ?&gt; </code> Details here: http://codex.wordpress.org/Template_Tags/wp_list_categories
list taxonomy based on taxonomy
wordpress
I have many post, all categorized. So 100 post, 40 in cat=4. All those 40 post have a custom field name point with a rating in there (how many point win). Si the question How to loop through all the post, and get ONLY the post with cat=4, and sort those post base on the point score in the custom field, and display, pos...
See WP_Query in Codex for info on how to query on custom fields . <code> $args = array( 'posts_per_page' =&gt; -1, 'cat' =&gt; 4, 'meta_key' =&gt; 'point_score', 'orderby' =&gt; 'meta_value_num' ); $points_query = new WP_Query( $args ); while( $points_query-&gt;have_posts() ): $points_query-&gt;the_post(); the_title();...
Custom loop request based on custom field
wordpress
I know this has come up a number of times but it is driving me nuts. I've spend hours trying to debug it. My AJAX isn't working for non-logged in users. Here's me action: <code> add_action('wp_ajax_nopriv_ah_update', array($tracker, 'update_tracking'), "1"); add_action('wp_ajax_ah_update', array($tracker, 'update_track...
You should end all "async" functions with die() or exit, otherwise WordPress does it for you returning -1.
AJAX and -1 response
wordpress
I'm using some code I found online to calculate the average value across all posts for [a_custom_field]. Does anyone know how to exclude (from calculation) any instances where the custom field = 0 or if the custom field has not been filled in? Or maybe there's a better method to get the same result. <code> global $wp_q...
Just tell the loop to continue if the custom field is 0 or blank. <code> if ((get_post_meta($post-&gt;ID,'60mins',true))||/*however it returns as blank*/) { continue; } </code> This will prevent it from being factored into the average.
Exclude empty fields from custom field calculation (Average)
wordpress
I'm developing a freemium wordpress plugin where "skins" will be available for purchase to customize the appearance of the plugin. If I commit an update to my plugin, it sounds like the contents of the "skins" folder inside of my plugin would be removed (since the skins don't come bundled with the core plugin), and the...
I'd suggest either using the database if possible or using a folder outside your plugin folder. A sub-folder of the <code> wp-content/uploads </code> appears to be a popular choice, as it survives updates/upgrades.
Maintaining plugin addons while upgrading
wordpress