question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
Is there any way to find out how much of disk space has been used by Media Library? My blog's media files stored in a separate folder named "media" rather than the default "wp-content/uploads". Thanks
Using stackexchange-url ("this StackOverflow Answer"), I came up with a Dashboard Widget that displays the following: I extended the OP request for the <code> uploads </code> dir size (default or custom location) and added <code> wp-content </code> (default or custom), <code> blogs.dir </code> case in Multisite, and Wo...
How to Check Disk Space used by Media Library
wordpress
I've been developing a WordPress site for a client on my own hosting and domain and within the next week I'll be moving it to theirs. I have a number of questions regarding this as this is my first time doing something like this. Once i've moved all the files and uploaded the database I plan to use the Search &amp; Rep...
Sounds like you know what you are doing that's a good start at a migration checklist :) FWIT ... Search and Replace is a very good plugin make sure you have a backup (my plugin DBC Backup 2 can help there) of your SQL database before you run it (just in case) Try to always set you're image and other URLs as relative (t...
About to migrate site to new domain
wordpress
For registered users to my blog, if they click on the dashboard, they get an alert suggesting that they tell the site administrator (me) that the new version of WordPress is available. All I want is to hide dashboard alerts from the subscribers. Where can I find the code to change this? I found a site here that suggest...
you can include some custom css in your functions.php that hides the update_nag (notifications) element dependent on user capability: <code> add_action('admin_head','admin_css'); function admin_css() { if(!current_user_can('administrator'))//not and admin { echo '&lt;style&gt;'; echo '.update_nag{display:none}'; echo '...
How do I disable dashboard update notifications for subscribers?
wordpress
I am the webmaster of Palo Alto High School's online publication, The Paly Voice. We're using Wordpress, and for some reason occasionally chunks of stories change fonts. Here is an example. I inspected it, and there's no surrounding element - just text. But why? How can I fix this?
The paragraphs that show up differently are not inside <code> &lt;p&gt; </code> tags. Therefore the font rule in your <code> story.css </code> file (line 111) does not apply to them. To fix this you can do one of two things: Put the paragraphs that are showing up with the wrong font inside <code> &lt;p&gt; </code> tags...
Font shows up as Arial instead of Times
wordpress
I have a php function that should print last three posts with title and excerpt. For the first post printed there is no excerpt. Here is the code: <code> $posts = wp_get_recent_posts( array('numberposts' =&gt; 3, 'post_status' =&gt; 'publish') ); foreach ($posts as $post) { setup_postdata($post); echo "&lt;h2 style='fo...
Excerpt is stored in database and available in post object only if it was added manually in post editor. Do not access such properties directly, use template tags instead - <code> get_the_excerpt() </code> in this case.
Excerpt not alway available
wordpress
Should custom user capabilities be added before the custom user role has been added, or the other way around? <code> add_role() </code> asks for and array of <code> $capabilities </code> in the third parameter of the function. <code> add_cap() </code> asks for a <code> $role </code> to apply the capability to in the fi...
There's a reason why <code> add_role() </code> has the <code> $capabilities </code> as 3rd parameter. First some insights on what happens, when you use the function. It calls <code> WP_Roles-&gt;add_role() </code> - the class method The method then does a check if the role already exists. If yes, it aborts. The next st...
Add custom user capabilities before or after the custom user role has been added?
wordpress
If someone enters the wrong URL to my wordpress multisite, they get the option to create another site in the network. Why does this happen, and how do I turn it off?
This setting is controlled under: Network Admin > Settings > "Allow new registrations." You may want "Registration is disabled."
Multisite, turn off "create new site"
wordpress
Straight to the question: It seems that there are only so many places to place custom code: functions.php, plugin, template, shortcode. Having too many plugins slows down your load times, inflating the functions.php file can get unmanageable, same with a template, and shortcodes really depend on the situation. I have a...
Organize your code by its purpose: If it creates output on the front end and requires changes in your theme's style sheet - it belongs to the theme. You don't have to put everything into the <code> functions.php </code> , split he code into several files if it helps. For example like this: <code> // extra functions jus...
Where to place custom functions?
wordpress
So I want to have defaults set up for each of my plugins settings, and I'm using wp_parse_args to do so which I believe is the correct way, but I'm hitting a roadblock. Here's my code at the moment: <code> function eddslider_options_each( $edd_slider_options ) { $edd_slider_options = get_option( 'eddslider_options' ); ...
Try: <code> function eddslider_options_each( $key ) { $edd_slider_options = get_option( 'eddslider_options' ); /* Define the array of defaults */ $defaults = array( 'slider_insert' =&gt; 0, 'slider_arrows' =&gt; 0, 'slider_bullets' =&gt; 0, 'slider_effect' =&gt; 'fade', 'slider_theme' =&gt; 'default' ); $edd_slider_opt...
Using wp_parse_args to set up Plugin Default Settings
wordpress
I'm exporting a Wordpress site from localhost to a web host, and I am unable to import the Media Library, as the web host is unable to contact localhost. I've uploaded all of the localhost files from /wp-content/uploads/..., and I'm thinking I just need to isolate the part of the MySQL database which contains the Media...
The Media Library lives in both wp_posts and wp_postmeta . wp_postmeta contains the image URL wp_posts contains an entry for each image insertion into a post, along with the post ID. Exporting and importing these 2 tables as SQL did not work for me - I received 'duplicate entry for key 7'... Exporting and importing the...
Where does the Media Library live in the database?
wordpress
I am not very familiar with WordPress so my knowledge with this is limited. I am working on a travel website where I need to show navigation menu and I am not sure how I can achieve the desired behavior. Here is my case: I need to show destination based drop-down menu and another as category based. Like <code> Destinat...
First, be sure your theme supports <code> wp_nav_menu </code> which is goes into a template file - such as header.php - with the template tag function <code> &lt;?php wp_nav_menu( $args ); ?&gt; </code> which also requires a function in functions.php. See http://codex.wordpress.org/Function_Reference/wp_nav_menu That w...
Creating a nav menu
wordpress
Here we have a snippet from a functions.php file... <code> add_action('init', 'create_recipes'); function create_recipes() { $recipes_args = array( ...some properies..., 'hierarchical' =&gt; false, 'rewrite' =&gt; array('slug' =&gt; 'recipes') ...maybe more properties... } register_post_type('recipes',$recipes_args); }...
In answer to my own question: It turns out the Wordpress permalink structure works perfectly well for custom types, e.g. example.com/recipes/lunch/sandwich/. This works exactly as expected if you set 'hierarchical' => true. What I was originally trying to do was unnecessarily difficult to execute, and requires properly...
Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
wordpress
I'm on a Category.php page which does the loop like this: <code> &lt;?php while ($wp_query-&gt;have_posts()) : $wp_query-&gt;the_post(); ?&gt; </code> I usually do a custom loop like this: <code> &lt;?php //Define the Loop $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query-&gt;query('posts_per_pa...
You can use the <code> pre_get_posts </code> action hook to set the order on your category archive like so: <code> add_action('pre_get_posts', 'filter_category_orderby'); function filter_category_orderby( $query ){ if( $query-&gt;is_category()){ $query-&gt;set('orderby', 'title'); } } </code> just paste this snippet in...
How to add orderby parameter for sorting on category.php
wordpress
Suppose I have written a <code> hello world </code> plugin, the main function is just print out a sting <code> hello world </code> . I want to print out <code> hello world </code> when I access the URL likes <code> http://example.com?plugin=helloworld </code> Is it possible to make the <code> hello world </code> plugin...
The Simplest way is to add a Query var to the list of query var that WordPress recognizes and check for that newly added query var on template redirect hook ex: <code> add_filter( 'query_vars', 'se67095_add_query_vars'); /** * Add the 'my_plugin' query variable so WordPress * won't remove it. */ function se67095_add_qu...
Can I call a custom plugin with a direct URL
wordpress
I am trying to add simple view counter for my advert and everything seems works fine with below code but only it is inserting each time new row on post "Update". What I want if the post id is exists than it should not add or modify anything into that table just ignore so view counter will use same row instead of multip...
why use a custom table for this? eliminate the whole <code> save_post </code> function and just use <code> get_post_meta </code> and <code> update_post_meta </code> to check/increment the view count. this is exactly what post meta data is for.
Check if post id exist in table than only update instead of inserting new row
wordpress
I am trying to embed a Ted talk video using the shortcode: <code> [ted id=myid] </code> But it's not working. It shows the text instead of the video. Is there any configuration I need to check to make it work?
Unfortunately, this is going to be a problem for you. The <code> [ted] </code> shortcode is specific to WordPress.com - not to a self-hosted site where you installed the software yourself from WordPress.org. The only embeds that WordPress.org's software supports by default are listed in the Codex : YouTube (only public...
TED talks shortcode not working
wordpress
Twenty Twelve comes with some page templates: Front Page &amp; Full Width. These are in the folder /page-templates. I've created my own template and saved it into this folder, but it is not present to be selected when editing a page. There is no mention of the two page templates in functions.php What do I need to do to...
Put the template file in your theme and add the following comment to the top of your file after the <code> /** * Template Name: This is the name of your template */ </code> WordPress will pick this up and in the page templates dropdown you will see "This is the name of your template" listed as an option
Create a new template for twentytwelve
wordpress
I am trying to add action hook in functions.php only if the page is <code> home.php </code> but the following does not work <code> if ( is_page_template("home.php") ) { // do stuff } </code> To make sure that file being used is <code> home.php </code> I do this <code> global $template; echo $template; </code>
Use <code> is_home </code> instead, as <code> is_page_template </code> will not work for <code> home.php </code> as its technically not a page template in the traditional sense. <code> add_action('template_redirect', 'are_we_home_yet', 10); function are_we_home_yet(){ if ( is_home() ) { //your logic here } } </code> Re...
Add action hook conditionally - only when home.php in use
wordpress
I'm new to using transients. Is this the proper format to create a transient and have it pull from the DB instead of using the http api? I have standardized my snippet so others can double check their code as well... <code> function google_transient() { $url = 'http://www.google.com'; $the_whole_body = wp_remote_retrie...
No quite: Get the transient’s content first, then do the expensive work to fetch the external resource. <code> function google_transient() { $transient_name = 'google'; $content = get_transient( $transient_name ); // done if ( $content ) return $content; $url = 'http://www.google.com'; $content = wp_remote_retrieve_bod...
Is this the proper usage of creating / using a transient?
wordpress
I'm building a custom search form with keywords and drop down lists (categories, date, and country (have a separate plugin for this)). In the searchform.php I have the input field and then select> option tags. <code> &lt;!-- searchform.php (form) --&gt; &lt;form action="/" method="get"&gt; &lt;input type="text" name="s...
That's certainly something you must solve on the server side, only omitting the arguments in URL would cause errors when accessing the non-existent keys in the <code> $_GET </code> array. You should build your arguments array dynamically based on whether the values are set ot not. Example: <code> $args = array(); forea...
Custom search form with empty parameters
wordpress
Simply put, I'd like to change the <code> wp_list_categories </code> output from this: <code> &lt;li class="cat-item cat-item-1"&gt;&lt;a href="http://mysite.com/category/articles"&gt;Articles&lt;/a&gt;&lt;/li&gt; &lt;li class="cat-item cat-item-7"&gt;&lt;a href="http://mysite.com/category/design"&gt;Design&lt;/a&gt;&l...
I am not sure if querying the categories again is the good idea. The following code extends the <code> Walker_Category </code> and makes use of it to do the replacement. Put the following in your functions.php: <code> class WPSE67791_Walker_Category extends Walker_Category { public function start_el(&amp;$output, $cate...
How can I make wp_list_categories output li with category-slug as class, for its children?
wordpress
I have a tech blog, what I want to do is to create an index page for articles in a certain category. For example, I want all the articles under the category "WordPress BasiX" to be arranged in an index (tabled preferably) at one page. Is there a way to do it in wordpress? Help please. My wordpress version is 3.4.2
There several different ways to achieve that: a custom template, a metabox, or a shortcode. In all cases you will probably use <code> get_posts() </code> or <code> WP_Query </code> to fetch the posts and some method to set the category. The following sample code illustrates that with a shortcode. Basic usage You just w...
How to create tabled index of posts in a certain category
wordpress
I'm writing a plugin and i wanted to i18n correctly text which i'm storing in the db or in an external file. How should i do that?As of now we are generating pot files with wordpress and so all the Translatable text is in calls <code> __( 'text', 'plugin_name'); </code> But there is some text i would like to store in t...
Short answer: You don't. Not with the I18N functions. Data in the database is data that can change, and should be translated via some separate means. Data in the code is hard-coded, and doesn't change, and can be translated via the I18N functions. If you want to store all your translatable text in a single PHP file as ...
How to i18n text coming from the db or from an external source
wordpress
I am wondering what the most efficient method is to add a javascript file specifically for a post and/or page. Here are a few solutions I came up with: Switch to HTML editing view and post your JavaScript in there (pretty bad solution) Custom fields with the specific JavaScript for that post/page in the key &amp; value...
I think the best balance between efficiency, and using proper wordpress methods for adding javascript would look something like this, as an example. functions.php: <code> function load_scripts() { global $post; wp_register_script( 'home', get_template_directory_uri() . '/js/home.js', array('jquery')); wp_register_scrip...
Most efficient way to add javascript file to specific post and/or pages?
wordpress
I'm working on a custom template for a new theme that uses a <code> WP_Query </code> instance to select posts from 2 post types with 2 custom fields that are NOT empty. Depending on the section of the site, a <code> $current_zone </code> variable may be set to determine the category to query from. <code> // Custom loop...
Custom field data is stored in the <code> postmeta </code> table, and it's likely that scanning through this table is causing slowness. You should: install the debug bar plugin which will give you more insight into the queries that are being executed against the database - you'll be able to see how long each query take...
WP_Query Performance Issues with meta_query
wordpress
I am using the query_posts function to list a 10 specific posts which lookup by post id. I have an array which looks like this.. <code> Array ( [0] =&gt; 17983 [1] =&gt; 17932 [2] =&gt; 18030 [3] =&gt; 18016 [4] =&gt; 17972 [5] =&gt; 18013 [6] =&gt; 18035 [7] =&gt; 17959 [8] =&gt; 18020 [9] =&gt; 18039 ) </code> I woul...
If the query is only for a small number of posts, then as linked to by Alex you can sort in php. However, this does not scale well. As suggested by Kovshenin - a better alternative is to use <code> posts_orderby </code> filter: <code> $post_ids = array(83,24,106,2283,14); $args = array( 'post_type' =&gt; 'post', 'post_...
Query Posts in a Predefined Order
wordpress
I need some help on how to correctly format this code snippet for translation: <code> &lt;?php next_post_link( '%link', __( '&lt;span class="meta-nav"&gt;←&lt;/span&gt; Nästa nyhet') ); ?&gt; </code> I've used this method in my theme before: <code> _e( 'Nästa nyhet', 'mytheme'); </code> But I don't know how to correctl...
Don't wrap the entire section in <code> __() </code> , just wrap the part you need to translate: <code> &lt;?php next_post_link( '%link', '&lt;span class="meta-nav"&gt;←&lt;/span&gt; ' . __( 'Nästa nyhet', 'mytheme' ) ); ?&gt; </code>
How do I translate this string - PHP syntax question
wordpress
I have created a custom taxonomy, this taxonomy is dedicated to image attachments, when I upload my images <code> $post-&gt;post_content </code> returns a string like: <code> '[caption id="attachment_98" align="alignnone" width="300"] &lt;a href="http://....jpg"&gt; &lt;img class="size-medium" title="title" src="http:/...
Filter <code> 'img_caption_shortcode' </code> . You get three arguments: an empty string, the attributes (including the attachment id), and the caption content. If you return anything but an empty string WordPress will print your return value instead of its own code. See <code> wp-includes/media.php </code> for details...
Converting the_content string to an array?
wordpress
Is there a way I can allow the user to attach images as attachments to a post without allowing him to insert them within the text itself? Ideally the Upload Media button remains the same but the image is not inserted within the text. The reason is I don't want users to start creating their own layouts and I want the te...
One way to do this would be to simply hide the upload/insert media button: and, then add featured image support for your themes posts, so a user can still attach images to the post. Hide upload/insert media button for your theme in: functions.php : <code> function hideUploadInsert($hook) { if($hook != 'post.php' AND $h...
Allowing post attachments without allowing to insert in text
wordpress
Live site. I'm using a custom header on my blog page which features the same coding as my regular heading for <code> nav </code> . The <code> nav </code> looks fine on all pages but the blog page- the Blog button shifts left. Any ideas why?
I'm not sure what's causing the causation of your problem, but for some reason the <code> &lt;li&gt; </code> tags are not being added around the "portfolio" menu item, when you visit the blog page. Maybe you can see why in the custom header menu code?! The <code> &lt;li&gt; </code> tags are what creates the spacing(pad...
custom header navigation has odd spacing
wordpress
<code> &lt;?php /* Template Name: second */ ?&gt; &lt;?php get_header(); ?&gt; &lt;?php query_posts(array('post_type'=&gt;'event')); ?&gt; &lt;?php if(have_posts()) while(have_posts()) : the_post(); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" class="entry"&gt; &lt;div class="thumbnail"&gt;&lt;?php the_post_thumbna...
You only need two small changes (1st and 3rd lines), though I also took the liberty of tweaking the classes on the div to what seemed more appropriate: <code> &lt;h1 class="title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt; &lt;div class="excerpt event"&gt; &lt;?p...
How to display only an excerpt of the content with custom post types?
wordpress
When I program a theme, I put WP-DEBUG on. Which ensure a proper PHP code. Sadly most Plugin developers keeps using non existing vars : <code> echo $args['title']; Notice: Undefined index: title in /wp-content/plugins/easy-fancybox/easy-fancybox.php on line 301 </code> Instead of <code> echo ( isset($args['title']) ? $...
I don’t know how to move the notices to the bottom or if that’s possible at all. To disable the debug mode in <code> wp-admin </code> write in <code> wp-config.php </code> : <code> define( 'WP_DEBUG', FALSE === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' ) ); </code> Untested: You could try to enable warnings in admi...
Hide php Notices in Dashboard
wordpress
I have several custom post types similar to (place, person,etc.) refer this and under each of these custom post type there are several posts inserted. (ex.http://www.firstpost.com/topic/person/amitabh-bachchan-profile-5605.html) Each post will be having the image attachments out of which I want to create a gallery page...
If you want to get all images attached to a single post then you can use this <code> if ( $images = get_posts(array( 'post_parent' =&gt; $post-&gt;ID, 'post_type' =&gt; 'attachment', 'numberposts' =&gt; -1, 'post_mime_type' =&gt; 'image',))) { foreach( $images as $image ) { $attachmenturl=wp_get_attachment_url($image-&...
create gallery page for specific post id
wordpress
I'd like to remove the action <code> profile_personal_options </code> (more specifically the color scheme and visual editor checkbox) which shows up in <code> wp-admin/user-edit.php </code> . I believe it's as simple as running it through <code> remove_action() </code> , but I'm not sure what the second parameter would...
Sometimes you need to get a little creative when customizing the WordPress admin area. It's often possible to do it without CSS, but it isn't always straightforward: understanding what's happening on the source files and digging through the many functions called in the ifs and elses is a must. Here's something slightly...
remove_action with profile_personal_options
wordpress
my shortcode output won't appear where I put it, but rather at the top of the content (top of the post/page content). And here is my code <code> function service_shortcode_index() { global $content; $output = include ( TEMPLATEPATH . '/service.php' ); return $output; } add_shortcode('service_mid', 'service_shortcode_in...
I think your problem is with the <code> $output = include .... </code> statement. <code> include() </code> returns true or false based whether it was successful - not the content of the file being included. Use output buffering to get the content. <code> function service_shortcode_index() { global $content; ob_start();...
Shortcode output always showing at top of page
wordpress
I am trying to get set the width, height and position of the Featured image for a new page I created.
To set the height and width of <code> the_post_thumbnail </code> use the following: <code> the_post_thumbnail( array(height,width)) </code> Where it would show in code like this: <code> if ( has_post_thumbnail() ) the_post_thumbnail( array(200,999)) </code> More Info on Post Thumbnails
How can I specify the width and height of the Featured Image in TwentyTwelve theme?
wordpress
I really have no idea how to figure out what exactly is wrong and so I'm seeking help here. When I try to validate my feed I get the following error message: <code> XML parsing error: &lt;unknown&gt;:8:17928: mismatched tag ... d/show_ads.js"&gt;/*&lt;![CDATA[*/&lt;p&gt;/*]]&gt;*/&lt;/script&gt;&lt;/div&gt;&lt;p&gt;The...
Well, Feedburner and AdSense don't work well together any more. Google is progressively shutting that down. You can read about it in their official "Spring Cleaning" announcement . But also, you likely have a major issue with your site in general. This is what I see when I try to visit your blog page: Now that your sit...
Feedburner doesn't work anymore
wordpress
I added the following function to the file <code> functions.php </code> <code> function contentGenerator($param) { if($param) { echo "Content true"; } else { echo "Content false"; } } </code> How can I call this function within a specific blog post or page?
If you are talking about a post's/page's content, it's not possible. Here are three different ways of solving your problem.The first way will give you the possibility to add the generated content inside your post's (or page's) content. The other two will be printed in one of your template files. E.g. in your <code> sin...
How to call function within a page/post, to dynamically generate content?
wordpress
I have two installs of wordpress on my server. Site 1. mysite.com Site 2. mysite.com/othersite The first wordpress install is located in mysite.com/wordpress, but is viewable at mysite.com, and the second install located in mysite.com/othersite, and viewable at the same address. I have page slugs activated for both sit...
You have to ignore the "otherside" in the htaccess file of your "root" blog. You can try to add something like that above the (root) WordPress' .htaccess code: <code> # stuff to let through (ignore) RewriteCond %{REQUEST_URI} "/otherside/" RewriteRule (.*) $1 [L] # </code>
Two installs conflicting - Pages redirecting
wordpress
I'm trying to isolate a wordpress installation on our site to a specific subfolder. I created a folder on our root site named <code> _wp </code> and placed all the wordpress files in there. I added the following rewrite rules to the htaccess in our root folder to allow permalinks within the wordpress installation to wo...
If you want your WP site to function completely in subfolder, just set it up there as usual (including <code> .htaccess </code> ) and do not add any directives to the root. Setup of <code> .htaccess </code> in root, while WP is in subfolder, is only necessary if you want to have core files (and so admin area) there, bu...
Isolating WordPress to a subfolder
wordpress
I am having trouble with adminbar in my site. I have buddypress installed on my site. i have disabled wordpress default admin bar using few lines of code. But it still showing i am pretty sure its coming from buddypress. is there any simeple lines of code that can remove top admin bar? I don't want to use plugin. Thank...
write this code in config.php This file is located in the root directory. <code> ** THis Will Remove disgusting Buddypress Top Admin Bar. Add this line of code at last of the previous codes and you are done */ define( 'BP_DISABLE_ADMIN_BAR', true ); </code>
How to disable buddypress top mini adminbar
wordpress
Here with the structure of content in text editor <code> Content Before &lt;!--more-&gt; Content After </code> I wanted to remove the "Content Before" in my single post so instead I have this <code> Content Before Content After </code> I will have the "Content After" on my single post only <code> Content After </code> ...
set the <code> $stripteaser </code> parameter to <code> true </code> ; <code> the_content('readmore', true); </code> http://codex.wordpress.org/Function_Reference/the_content
Remove Content after tags
wordpress
I'm wondering why WordPress does not support sessions and many people out there claim that putting the following code in functions.php might not be a good idea (it in fact works for me but returns PHP warnings, too): <code> function cp_admin_init() { if (!session_id()) session_start(); } add_action(‘init’, ‘cp_admin_in...
The reason for not working <code> $_SESSIONS </code> in WP Core: The thing WordPress is doing with sessions is burdened inside <code> ~/wp-includes/load.php </code> . The responsible function for resetting the <code> $_SESSION </code> to <code> null </code> is <code> wp_unregister_GLOBALS() </code> . So in case you rea...
Enable WordPress Sessions
wordpress
Making a site for a client, I have some pages that the client won't be able to edit or delete. These pages rely on specific page templates. However, I don't want these templates to be available for the client when creating new pages. Is there someway to hide these certain page template from the page attributes dropdown...
Rather than defining them as custom page templates, you have an alternative. Use the page specific templates, e.g. for a profile page, with the slug <code> profile </code> you could create a <code> page-profile.php </code> in your theme, or you can use <code> page-21.php </code> where <code> 21 </code> is the ID of tha...
How to make certain page templates visible to admin only
wordpress
On my site I have a number of parent pages with associated child pages. How can I show all the child pages of one particular parent when a visitor is either on the parent page or one of it's children? For example; If someone clicks onto the "Story" parent page, they'll see a list of "story" child pages in the sidebar (...
<code> Add this code in sidebar.php.this code will help you. global $post; $parent_id = $post-&gt;post_parent; if(!empty($parent_id)){ $parent_post=get_post($parent_id); echo '&lt;h1 class="entry-title"&gt;'.$parent_post-&gt;post_title.'&lt;/h1&gt;'; echo '&lt;ul&gt;'; $children = wp_list_pages('title_li=&amp;child_of=...
Show child pages when on a child page
wordpress
I have the following URL structure: <code> http://localhost/wordpress/gallery?id=331 </code> <code> id </code> specifies the <code> id </code> of the post. <code> gallery </code> is a normal page inside which I am accessing the <code> id </code> of the post and fetching the attachment images using <code> WP_Query() </c...
I have tried some add_rewrite_rule magic and query variables and it worked. Thanks for the help everyone. If in case anyone want to refer the answer: <code> add_filter( 'query_vars', 'wpse26388_query_vars' ); function wpse26388_query_vars( $query_vars ){ $query_vars[] = 'custom_gallery_id'; return $query_vars; } add_re...
Rename page URL
wordpress
Doing a site for an architecture firm. Want to organize this very intelligently. I know of a lot of different ways to do what I'm about to explain, but I want to know the most efficient way/most easily understandable way for the client. Let's assume there are industries. We'll use Sports. Underneath Sports, there are P...
I believe that CPT-onomies may do what you're looking for. The plugin allows you to use a post type as a taxonomy, so you would set up Team Members as a post type and include their post information, but then be able to use each post as a custom taxonomy as well. As for the other issue, parent/child post types is anothe...
Hierarchical Custom Post Types or Similar
wordpress
I have some custom code built into the header of my theme that gets the featured image from a post, displays the image and links to the posts permalink when clicked on by a user. The problem I am having is that I have this happening on 2 different divs pulling in info from 2 different categories, but when you hover ove...
For both loops move <code> &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt; </code> To after <code> while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post(); </code> <code> the_permalink() </code> is template tag and as such generates what it does, based on global <code> $post </code> variable. In your custom ...
Multiple instances of Featured Image Query
wordpress
I'm working on a new plugin but it's my first to save which will save an option to the database. Currently I'm using <code> add_option </code> and I assumed that - activation would fail or - the wrong value would be saved to the wp_blogID_options table because I wasn't using <code> add_blog_option </code> . All the pos...
What I've come to 'learn' is that there are 3 states on plugin activation for a mulitsite setup. Consider this for a Site Admin who installs a new plugin: Plugin is network activated - but it needs admin to complete setup (call it stateless) Plugin activated, no 'unique features' per blog and it doesn't need an admin u...
What is wrong with using add_option with Multisite instead of add_blog_option in a plugin
wordpress
I have about 50 users. Its pretty easy to list them all. However they are related to a special custom post type through a postmeta field called wpp_agents. So I need to list Users, but also the post title(linked to the post). User 1 | User 1's Post(linked) User 2 | User 2's Post(linked) etc... I am a mysql noob but get...
Gladly there's a function that will output exactly that query string for you (still laughing about it :) ). Here it is: <code> get_posts_by_author_sql </code> @queryposts.com , which looks in the core source like this . In detail it builds the <code> WHERE </code> part for you, that you can drop into your query. So jus...
how would I create a custom query to get all users, and a related post based on a postmeta field?
wordpress
I am working on a custom Wordpress template for the archive. I have the archive set up by category but now I want to organize by category and month but I can't figure out how to access the month argument from the permalink. How would I get access to that argument.
the standard WP function for that is: <code> the_date(); </code> ( source )
How to get the month argument from permalink in wordpress?
wordpress
On my site, I want some pages to not be queriable by the search form (so they don't appear when I've got something like www.ex.com/?s=banana) Is there a way to "Remove" pages from the search results page (without just blindly do a condition of if is_page(id), display:none)
In WP_Query() there is a 'post__not_in' argument where you can exclude specific post ID's. You would create a new WP_Query inside of your search.php and use the current $query_args, then add on your 'post__not_in'. If you wanted to make it more dynamic, you could also build in some post meta where you could do a meta q...
Remove some pages from search
wordpress
I started using the JSON API plugin. It works good ! But the problem i am facing is, If i enter any text containing special characters through CMS The output is not same as the given text. Why this is happening? Example: It's a good app (Input) The output looks like It &#039; s a good app. Please suggest any tips/metho...
That's probably because the "JSON API plugin" htmlescapes your text. So if you would just display it on site it should print OK, but if you need to work with it on the backend than just use <code> html_entity_decode() </code>
How to replace or display the special characters from JSON API plugin
wordpress
I am using bbPress on my site and have (bbPress) Login Widget on my sidebar. Is there a way to change the default image size from 40 to 80 or other number? here is the code from the core files: <code> &lt;?php echo get_avatar( bbp_get_current_user_id(), '40' ); ?&gt; </code> How do I change that default 40 px without e...
You can filter <code> 'get_avatar' </code> : <code> add_filter( 'get_avatar', 'wpse_67657_new_avatar', 10, 5 ); function wpse_67657_new_avatar( $avatar, $id_or_email, $size, $default, $alt ) { // create a new img element or … $new = str_replace( 's=40', 's=80', $avatar ); $new = str_replace( 'avatar-40', 'avatar-80', $...
Change the avatar ratio in bbPress login widget
wordpress
I have a custom post status which should be public visible but not displayed in the "all" list of the edit screen. This is how I register the post status: <code> register_post_status('my_custom_post_status', array( 'label' =&gt; __('The Label', 'domain'), 'public' =&gt; true, 'exclude_from_search' =&gt; true, 'show_in_...
This solves my problem: <code> register_post_status('my_custom_post_status', array( 'label' =&gt; __('The Label', 'domain'), 'public' =&gt; !is_admin(), 'exclude_from_search' =&gt; true, 'show_in_admin_all_list' =&gt; false, 'label_count' =&gt; //blablabla )); </code> <code> !is_admin() </code> makes the status only pu...
register_post_status and show_in_admin_all_list
wordpress
I would like to try build a simple plugin that collects and stores the name and email address of the person who filled in the form. I realize there are probably dozens of plugins out there that do this already but would like to build my own, for practice. If the user enters their name and email address, where should th...
There are multiple storage mechanisms in WP so it can be bit tricky to pick one and sometimes there is no single right choice. Let's examine your criteria for storage: persistent (you don't want data just evaporating) processable (you want to export it and probably navigate) simple to implement (you don't want go build...
Building an email signup form. Where should the information be saved in the DB?
wordpress
I need to sort (custom) posts by 2 custom field values... custom field name 1: <code> is_sponsored </code> [ value can either be <code> 1 </code> or <code> 0 </code> ] custom field name 2: <code> sfp_date </code> [ <code> timestamp </code> aka current post date in seconds ] Posts whose " <code> is_sponsored </code> " v...
OK, the final workaround would be to split query: <code> $sfp_query_args = array( 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'sfp_post_category', 'terms' =&gt; $cat_id_arr ) ), 'meta_key' =&gt; 'is_sponsored', 'post_type' =&gt; 'sfpposts', 'post_status' =&gt; 'publish', 'showposts' =&gt; (int)$per_page, 'paged' =...
meta_query sorting by 2 keys
wordpress
I've made a custom function that retrieves the custom taxonomy term for a list of posts in a query, and echos both the name and the link. Additionally, it also excludes listing a term if I specify the term id (I have a special term, which I don't want displayed, that I use as a loop hook). This is achieved by this func...
Here's more of a complete guide based on the <code> $wp_query </code> object: The Taxonomy First you might want to know in which taxonomy you are, what its name is and retrieve all its available data from the object. <code> // Taxonomy name $taxonomy = get_query_var( 'taxonomy' ); // Taxonomy object get_taxonomy( $taxo...
Return only the custom sub-term for custom post type, do not echo term-parent
wordpress
As the name of the thread indicates, I want to add to my website a Facebook 'Share' and 'Like' buttons to each of my individual posts. On each post page I will have those two buttons so people can like or share that individual page. I can't seem to find a way to do that, so i would like to ask you guys how can i achiev...
Install 'Simple Facebook Connect' Plugin. Go to 'Simple Facebook Connect' under 'Settings' in WordPress Admin. Configure the plugin. There is a help tab to help you. Enable 'Like Button' and 'Share Button' modules. Change the 'Like Button Settings' according to your requirements. You are done. More Info This plugin is ...
Facebook 'Share' and 'Like' on individual posts
wordpress
I want to know if it is a good practice according to WordPress theme or plugin development. <code> add_action('init','all_my_hooks'); function all_my_hooks(){ // some initialization stuff here and then add_action('admin_init',-----); add_action('admin_menu',----); // more like so } </code> thanks
In general: Yes, wait for a dedicated hook to start your own code. stackexchange-url ("Never") just throw an object instance into the global namespace. But <code> init </code> is rarely necessary. You hook in as late as possible. If your first code runs on <code> wp_head </code> do not use an earlier hook. You can even...
Use wp init hook to call other hooks?
wordpress
I am trying to use <code> &lt;?php echo get_the_category_list(); ?&gt; </code> in my <code> footer.php </code> file to display my categories. On the home page, this function is showing only two categories and in inner single posts it shows that post's related category. In pages, this tag shows nothing. I have even trie...
<code> get_the_category_list() </code> shows categories that have been assigned to a particular post/page. If you want a list of all categories you've defined then you should use <code> wp_list_categories() </code> ( Link to Codex )
get_the_category_list() does not give me all my categories
wordpress
Read up on this, and I believe I'm doing everything right. Everything is getting loaded in the footer. Here is my code: <code> function load_kenburns() { if ( !is_admin() ) { wp_register_script( 'kenburns', get_template_directory_uri() . '/js/bannerscollection_kenburns.js', '', '', false); wp_register_script( 'jquery-u...
Write wp_enqueue_script in wp_enqueue_scripts action <code> function load_kenburns() { if ( !is_admin() ) { wp_register_script( 'kenburns', get_template_directory_uri() . '/js/bannerscollection_kenburns.js', '', '', false); wp_register_script( 'jquery-ui', get_template_directory_uri() . '/js/jquery-ui-1.8.16.custom.min...
wp_enqueue_script won't load in header?
wordpress
I am using a small shortcode to output a list of movie titles arranged by decades. <code> decades </code> is my custom taxonomy with terms like <code> 1930s </code> <code> 1940s </code> etc. Here is my shortcode: <code> [fashionfilms type=fashionfilms tax=decades] </code> and here is how that shortcode is parsed: <code...
You've used <code> wp_reset_query </code> , however, you should use <code> wp_reset_postdata </code> . <code> wp_reset_query </code> takes the current query object, and replaces it with the main query. The problem here however, is that you're using WP_Query, which is a separate individual query object, the main query h...
Why is my WP_Query outputting my entries twice?
wordpress
I have a plugin that does validation on user submitted comments. When validation fails, I want to redirect them back to the comment form, and have their comment still appear in the comment box, so they don't have to type it again. How can I add custom content to the comment form #content textarea?
You can filter <code> 'comment_form_defaults' </code> to change the <code> textarea </code> . You get an array with the default fields as argument: <code> add_filter( 'comment_form_defaults', 'wpse_67503_textarea_insert' ); function wpse_67503_textarea_insert( $fields ) { if ( /* your condition */ ) { $fields['comment_...
How to add text to comment form #content textarea?
wordpress
I am stuck at <code> add_custom_background </code> . I can change background color/image but I only want to change my index page. Currently, the changes apply on the whole page. I want to make the changes from WP-admin. How can I specify it to a specific page ? Edit: I just checked im running 3.3.1. So my version is no...
You can check in your callback function if you are an the front page. Sample code for the theme’s <code> functions.php </code> : <code> add_action( 'after_setup_theme', 'wpse_67480_theme_setup' ); function wpse_67480_theme_setup() { $bg_options = array ( 'wp-head-callback' =&gt; 'wpse_67480_background_frontend', 'defau...
Custom background for the index page only?
wordpress
I'm using this bit to insert/update a custom post type from the front-end. The date is set from a custom jquery datepicker. <code> if (strtotime($date) &lt; strtotime('tomorrow')) { $newpostdata['post_status'] = 'publish'; } elseif (strtotime($date) &gt; strtotime('today')) { $newpostdata['post_status'] = 'future'; $ne...
Answer couldn't be simpler. As pointed out by stackexchange-url ("Otto") at the wp-hackers list, problem was me not setting <code> post_date_gmt </code> when using <code> wp_update_post() </code> . Final code looks like this: <code> if ( $post_date &lt; strtotime( "tomorrow" ) ) { $status = 'publish'; $newpostdata['pos...
wp_update_post() doesn't update post_status?
wordpress
I want to pass get_option value to an array value. This the value that I want to pass to the array. <code> &lt;?php echo stripslashes(get_option('a')); ?&gt; </code> and this is what I am trying to do. <code> &lt;?php $var = array( 'foo' =&gt;'echo stripslashes(get_option('a'));'); </code> Please let me know how can I ...
Use a simple variable to store the value. <code> $a_val = stripslashes(get_option('a')); $var = array( 'foo' =&gt; $a_val); </code>
Pass get_option value to an array
wordpress
In functions.php of my theme I have code to add page in admin area and append scripts to it. But scripts are not loaded. Bellow is code. Commented out add_action lines are the one I did check. <code> // functions.php // Append user style and scripts to Add New Wallpaper menu function pb_admin_scripts() { wp_enqueue_scr...
Use <code> add_action('admin_enqueue_scripts', 'pb_admin_style'); </code> and as the manual states, the <code> admin_enqueue_scripts </code> can also be used to target a specific admin page. Use this to only select the admin page you want. <code> function pb_admin_style($hook) { if( 'edit.php' != $hook ) return; wp_enq...
Adding scripts to admin page in my theme
wordpress
I created a page and I set the template as showcase and then I went to setting-> reading and as a static page I choose my created page. I'm wondering how I can add slideshows with pictures and sticky posts. I went to documentation in the link but unfortunately I couldn't find anything.
Welcome ... this forum is more suited for WordPress selfhosted not WordPress.com sites. However ... reading the WordPress.com theme documents it says The Showcase page template offers a featured slider for sticky posts. If you’d like a post to appear in the slider, mark it as sticky and assign it a featured image that’...
how to use the slide show of Skylark in showcase?
wordpress
I have a custom post type: <code> add_action( 'init', 'register_cpt_foto' ); function register_cpt_foto() { $labels = array( 'name' =&gt; _x( 'Fotoalbums', 'foto' ), 'singular_name' =&gt; _x( 'Fotoalbum', 'foto' ), 'add_new' =&gt; _x( 'Nieuw fotoalbum', 'foto' ), 'add_new_item' =&gt; _x( 'Voeg nieuw fotoalbum toe', 'fo...
[Comment reposted as answer at request of OP author:] Rather than deleting them, why don't you add your post_type to the if() statement: <code> //Don't process anything but POSTS and PAGES (i.e. no revisions) if( $data['post_type'] != 'post' &amp;&amp; $data['post_type'] != 'page' &amp;&amp; $data['post_type'] != 'foto...
Make a magic tag work with Custom Post Types
wordpress
I am trying to create a function to add data from two custom fields after the entry title. I get it to show correctly when these fields are filled in. The fields are a image source url and an url the image has to link to. The problem is that it's taking up space even when the custom fields are empty. My php skills are ...
There are a few issues that break your code: <code> $post </code> doesn't exist, you'd need to import it using <code> global </code> , or simply use <code> get_the_ID </code> as you're already doing <code> $check[''] </code> won't return anything since it will access an undefined index, outside of the <code> empty </co...
Hide custom fields when empty
wordpress
I found this very useful code at the wp codex, it basically lists out the parent, child and grandchild pages, I'm using it in my sidebar and it works well for the parent and children pages, but when you go to a grandchild page, the menu changes and it now only shows the child/grandchild, instead of the same menu on the...
I finally figured this out. I didn't want it to show up at all on pages without children, so the first if statement checks and only displays the menu if the parent has children. This menu stays the same whether you are on the parent, child, or grandchild page. :) <code> &lt;?php if ( has_children() ) { //makes menu tit...
Subnav menu - adapt to show the same on parent, child & grandchildren pages?
wordpress
I have a built a Wordpress site that enables comments on pages and I am using them as reviews , what I would like to do is for someone to be able to make a comment on a page without being on that page. http://universitycompare.com/university-guide/anglia-ruskin-university/ On the link above, the top right, there is a l...
You have to set the value of <code> $_POST['comment_post_ID'] </code> to the post id of the page: <code> &lt;input type='hidden' name='comment_post_ID' value='10' /&gt; </code> Then set the <code> action </code> of the form element to <code> /wp-comments-post.php </code> , filter <code> 'comment_post_redirect' </code> ...
Making a Comment on a page without being on that page?
wordpress
I have a Wordpress 3.4.1 installed on a local WAMP server. I am in the process of upgrading it to a network, but I now realise my admin account has no admin privileges: No access to the Updates page (update-core.php) - I receive "You do not have sufficient permissions to access this page." No ability to install plugins...
I've just done a new install of a newly download zip file, and the installation process stops at: <code> http://localhost/site/wp-admin/install.php?step=2 </code> This page is blank, and nothing progresses. I now recall this happened on my previous installation also. If I refresh this page, I receive a message: "Alread...
local WAMP admin user has lost privileges
wordpress
I am working with category.php. I have my posts returning how I want them, I am getting the child categories how I want them but now I am trying to add pagination and limit the amount of posts to 3. When I ran my test, the 4th post showed up on the page. I was expecting only 3 and the pagination at the bottom. I am not...
I changed the first line of my code to this and it worked to limit the posts <code> $allcats = get_categories(array('child_of' =&gt; get_query_var('cat'), 'number' =&gt; 3,'order'=&gt; 'asc')); </code> Now on to the next problem...Pagination
limit posts per page
wordpress
For all the pics I upload to Wordpress I get such a link to the pic: <code> src='http://myblog.com/wp-content/themes/mytheme/thumb.php?src=wp-content/uploads/2012/06/mypic.jpg&amp;w=100&amp;h=100&amp;zc=1&amp;q=90' </code> Anf ofcourse Wordpress does not find it. But if I change to with the firebug: <code> src='http://...
Seems to me you use a WordPress theme which uses some kind of php library to resize images. You should really use WordPress default <code> add_image_size() </code> and <code> wp_get_attachment_image </code> but if you were the one who created the theme you would already know that. There are 3 things you can do: find a ...
Missing thumbnails
wordpress
I noticed while looking at the HTML of an edit page that WordPress uses a lot of hidden input elements for storing nonces. Is there a significant advantage to using either this style of storing nonces for AJAX use or using those stored via the <code> wp_localize_script </code> style?
Depends, will the form work with AJAX turned off? If so use an input and degrade gracefully. Otherwise, define nonces used by JS using JS for consistency, and to prevent grabbing stuff from the DOM
Nonce best practices: hidden input vs. wp_localize_script?
wordpress
How do I add a favicon that only shows during viewing of my plugin's admin panel? I mean, what event do I intercept?
When you add your admin (sub)page, then you're (hopfully) using <code> add_*menu_page() </code> . You can simply save its result in a var. This var is the <code> $hook_suffix </code> . Then you can simply add your callback (that adds the favicon) to the <code> admin_head-{$suffix} </code> hook Source Link . As the plug...
How do I add a favicon that only shows during viewing of my plugin's admin panel?
wordpress
I'm looking for some help tying in with the wpdb to compare and change certain values. I'm very novice with mysql handling so I really appreciate any help on this matter! What I want to do is to go through the wp db looking for a post same id as <code> $page_id </code> . When the post is found it should check the <code...
This is what I ended up using, turned out I didn't need to apply the meta value to the child pages since I used another approach. Hopefully it's useful for someone. <code> $row = $wpdb-&gt;get_row("SELECT * FROM wp_posts WHERE ID ='$post_id'"); $new_order = $order[$page['depth']]; $new_order = $wpdb-&gt;escape($new_ord...
Compare string with post id in wpdb and do stuff when match is found
wordpress
I'm looking for a way so that I can delete category's name in the pages. I tried to find something for category in index.php but I couldn't find anything. Please help me to solve this problem. Thanks in advance
What theme are you running? Are you referring to Pages or Posts because they are two different types or rather, what we call Post Types . Pages are normally controlled via your <code> page.php </code> template file Posts are normally controlled via your <code> single.php </code> template file Commonly you will find cat...
delete category name in the pages
wordpress
I'm testing for a certain fixed post on an about page, I guessed that the best way is to test for post title (?). Here's my code, what's going wrong? <code> &lt;?php if (is_page()) { $cat=get_cat_ID($post-&gt;post_title); $posts = get_posts ("cat=$cat&amp;showposts=35"); if ($posts) { foreach ($posts as $post): setup_p...
First off all, <code> $post </code> is one of the WordPress core global variables and as such should either not be touched or reset after your <code> foreach </code> loop. Using <code> setup_postdata() </code> allows you to make use of template tags such as you are doing in the above snippet with <code> the_title() </c...
Testing for post title in 'if/else' statement returns no content
wordpress
I'm trying to set the post_date via XML-RPC and keep getting an error saying the XML isn't formatted properly. The code goes something like: <code> $post = get_post( $post_id ); $response = $client-&gt;query( 'wp.editPost', array( 0, $user, $pw, array( 'post_date' =&gt; $post-&gt;post_date ) ) ); </code> I'm hitting th...
There are a couple of issues here. First of all, <code> wp.editPost </code> takes a fourth parameter before the content struct -> the ID of the post you're trying to edit (should be an integer). Second, you're passing a string for the <code> post_date </code> , so the client automatically converts this to a <code> &lt;...
XML-RPC and post_date
wordpress
I have this php code below for displaying the post from the specific categories. <code> &lt;ul id="sliderx"&gt; &lt;?php query_posts('category_name=slideshow&amp;showposts=10'); while (have_posts()) : the_post(); echo "&lt;li&gt;".the_content()."&lt;/li&gt;"; endwhile;?&gt; &lt;/ul&gt; </code> as you can see, it displa...
That happens because <code> the_content() </code> contains already an <code> echo </code> . PHP tries to create the string before it sends it to the <code> echo </code> command. While the string is evaluated the content will be printed already. Then <code> echo </code> gets what was not yet printed: the <code> li </cod...
displaying the categories post
wordpress
Struggling to get the format right for the PHP in this do_shortcode embed using variables from Advanced Custom Fields plugin. I think I've tried every variation on ., ', and ". After reading every resource I could find I'm still no closer. <code> &lt;?php $address = get_field('cong_streetaddress'); $city = get_field('c...
Your syntax is broken, the quote marks do not match. Try to separate data from the shortcode template, and use <code> sprintf() </code> : <code> $shortcode = sprintf( '[pw_map address="%1$s %2$s %3$s %4$s" width="%5$s" height="200px"]', $address, $city, $province, $postalcode, '100%' ); echo do_shortcode( $shortcode );...
Using do_shortcode with variables?
wordpress
I'm using the plugin Post from site , which sets up a WP front end writer. I changed some line of code because I need to select categories with checkboxes and not with a multiple select (as it was originally in the plugin). Unfortunately it doesn't work: there is a checkbox in the front end writer, now, but checking bo...
You changed the checkbox's name attribute value. You should use the same name value: terms[$taxonomy][] This should fix the code: <code> if (is_taxonomy_hierarchical($taxonomy)) //$out .= "&lt;input class='{$term-&gt;term_taxonomy_id}' type='checkbox' value='{$term-&gt;term_taxonomy_id}' name='{$term-&gt;term_taxonomy_...
Categories from front-end, checkbox selection doesn't work
wordpress
I'm trying to get page content when I only know the slug string. Is there a function for this, or an easy way to do this or is this a case of doing it via SQL? Thanks very much
Use <code> get_posts() </code> and the parameter <code> name </code> which is the slug: <code> $page = get_posts( array( 'name' =&gt; 'your-slug' ) ); if ( $page ) { echo $page[0]-&gt;post_content; } </code> Be aware that the post type in <code> get_posts() </code> defaults to <code> 'post' </code> . If you want a page...
Get page content using slug
wordpress
With get_users() I am listing users and their information. I've a custom field in the database, people_lists_class. <code> &lt;?php $blogusers = get_users('role=contributor&amp;orderby=display_name'); foreach ($blogusers as $user) { echo '&lt;li class="person member"&gt;' . '&lt;a href="' . get_author_posts_url($user-&...
When you have that much code to output concatenating it into one string like that makes it very difficult to read for others and yourself, also, to debug when things go wrong. Try this method for concatenating your output, <code> $blogusers = get_users('role=contributor&amp;orderby=display_name'); foreach ($blogusers a...
Echo text if field under user_meta is empty with get_users()
wordpress
If an unregistered user/stranger try to view a post it says "You must be registered or logged in to view the post". http://testandverification.com/events/dvclub-august-2012-on-sv-uvm/ We have a category (for private posts) to allow only some registered users to access some posts. Even though posts are not included in t...
It is a strange and rare bug. While publishing our last post we checked the "Blog" and some other categories in the category section. In our previous posts we never checked the "Blog" category. Initially, when I tried to reproduce the bug, I didn't noticed it. We again tried to reproduce the bug and this time we have i...
how to allow unregistred users to view normal posts
wordpress
So, I am new to PHP, so I'm hoping to do this with a plugin, if possible. We are hosting on Heroku, this means uploading a local image to /uploads isn't going to work for this. We need to be able to reference the individual user's avatar from our hosting at Amazon s3 (they don't need to be able to upload it themselves,...
The function that does all the heavy lifting for avatars is <code> get_avatar </code> . It's a pluggable function , meaning you can replace it with a plugin. Get avatar also has a handy filter you can use to override things programatically. So, a few options: (1) completely replace <code> get_avatar </code> which might...
Using Heroku, need to have non-gravatar avatars, but not stored locally
wordpress
I want to add a custom font into my theme. Please let me know if this is just as simple as uploading the font to a new folder named "fonts" and then changing the css and renaming the font-family property there or it's somewhat different procedure. I am not sure about it. Please help me.
To use a custom font, simply upload the font to your theme folder and then add a CSS <code> @font-face </code> declaration to the top of your theme's <code> style.css </code> file pointing to the new font: <code> @font-face { font-family: CustomFont; src: url('CustomFont.ttf'); } </code> You can then reference that cus...
How to add a custom font in a theme
wordpress
Right now when I log out via: <code> &lt;a href="&lt;?php bloginfo('url'); ?&gt;/wp-login.php?action=logout"&gt;Log out&lt;/a&gt; </code> it redirects me to the page where I need to confirm the log out. How to eliminate the confirmation and redirect to the homepage after logout?
This happens because you are missing the neccessary nonce in the URL, which is being checked in <code> wp-login.php </code> <code> case 'logout' : check_admin_referer('log-out'); ... </code> Use <code> wp_logout_url </code> in order to retreive the URL including the nonce. If you want to redirect to a custom URL, simpl...
How to log out without confirmation 'Do you really want to log out?"?
wordpress
Basic loop question: I have a custom post type with a custom taxonomy and 3 terms. On the archive page (archive-custom_post_type.php), I would like to display one post from each taxonomy term. Is this possible within the standard <code> if (have_posts()) : while (have_posts()) : the_post(); </code> loop, or do I have t...
So I went ahead and did the multiple loop thing, as I had done before. I'm always interested in seemingly cleaner/simpler solutions, but sometimes you just have to keep moving. This is the code I'm using: <code> &lt;?php $args = array( 'post_type' =&gt; 'projects', 'project_category' =&gt; 'websites', 'orderby' =&gt; '...
CPT archive page - show one post from each taxonomy term
wordpress
How to display posts with 'Event' custom type ordered by 'Start_Hour' and then by 'Start_Minute'? 'Start_Hour' and 'Start_Minute' are numeric custom fields. I tried this, but it doesn't work: <code> $args = array( 'post_type'=&gt;'Events', 'orderby' =&gt; 'meta_value', 'meta_key' =&gt; 'Start_Hour Start_Minute', 'order...
Thanks to stackexchange-url ("Bainternet") I found the solution: <code> function orderbyreplace($orderby) { return str_replace('menu_order', 'mt1.meta_value, mt2.meta_value', $orderby); } </code> and... <code> $args = array( 'post_type'=&gt;'Events', 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC', 'meta_query' =&gt;...
How to order custom post type by multiple custom fields?
wordpress
I'm using the Roots WP Theme and for some reason when copy pasting the page-custom.php to create a home page template. The new homepage template is showing the sidebar but not the original page-custom template even though the two template files are exactly the same at this moment. Can anyone explain why this might be?
Look at the <code> config.php </code> : <code> function roots_display_sidebar() { $sidebar_config = new Roots_Sidebar( /** * Conditional tag checks (http://codex.wordpress.org/Conditional_Tags) * Any of these conditional tags that return true won't show the sidebar */ array( 'is_404', 'is_front_page' ), /** * Page temp...
Two exact templates, sidebar showing in one but not the other
wordpress
I have one loop for big images, and I need the same loop with small images (thumbnails). This is where I am stuck. Use case: I am trying to implement the elastic image slideshow jQuery plugin with WordPress following this tutorial . So far I was able to get the large images but I can't figure how to manage the thumbnai...
You don’t need a second loop. Just save all the data you need later during the first loop. Sample code, not tested, just a hint: <code> &lt;ul class="ei-slider-large"&gt; &lt;?php // Here we store the data. $second_loop = array(); // Main loop $main_query = new WP_Query( array( 'category_name' =&gt; 'featured', 'posts_...
How to create an identical second loop for attachments?
wordpress
I've added multiple custom image sizes using the <code> add_image_size </code> function. The problem here is when I need to update the proportions of these sizes, the changed sized won't apply. My guess is that wordpress inserts those sizes in the database and it fails to update them upon code change. How can I update ...
With this plugin you can choose which specific image sizes should be updated: AJAX Thumbnail Rebuild Or you can use Simple Image Sizes , too. More infos on wpbeginner .
How to update custom image sizes?
wordpress
Rich Snippets look like a good tool for the webmaster's toolbox. Do you know of any way of integrating Rich Snippets into Wordpress?
To be clear, the Rich Snippets tool is purely for testing what the formatting/markup of your content is already. It does nothing on its own. Most of the markup that the tool is looking for is usually baked into a theme. WordPress helps this along a little bit by incorporating parts of the hAtom format into the <code> b...
Rich Snippets for Wordpress
wordpress
I need to figure out a way to add share links to each blog post on the homepage. This way users can share specific posts without actually going into the post. Is there a way to do this easily through a WP plugin? The only tricky thing to me is they will be sharing URLs from pages which they are not actually on so I'm u...
There's an option to do this in Jetpack, if you have sharing tured on. Just click on "Front Page, Archive Pages"... etc Then it'll show up on the homepage, for example on my homepage:
Add share links to all blog posts on homepage
wordpress
I'm currently using <code> get_field </code> with Advanced Custom Fields plugin ( see here ) to get a single image for search results. The end result is that these pages are loading slow, as I believe this is due to MySQL returning the whole array of all images in the gallery for the specified page, which ends up being...
I have managed to work it out - the function was leading to a lot of queries, so I rewrote it as follows: <code> $housePhotos = get_post_custom_values('house_photos'); $housePhotos = explode(';',$housePhotos[0]); preg_match_all('`"([^"]*)"`', $housePhotos[1], $results); $imageURL = wp_get_attachment_image_src( $results...
Website loading slowly - Advanced Custom Fields images
wordpress
I have Googled for a while and I am not sure how is the best way to do this. In <code> wp-includes/general-template.php </code> I am looking at the function <code> wp_get_archives() </code> which has this line of code in: <code> $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'p...
A WordPress filter is a function that takes in a string, array, or object, does something to it, and returns that filtered string, array, or object. So what you want to do is turn <code> "WHERE post_type = 'post' AND post_status = 'publish'" </code> into <code> "WHERE post_type = 'post' OR post_type = 'events' AND post...
Overriding wp_get_archives() apply_filters()
wordpress