INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
How to display terms and conditions in post area?
I'm running a multisite.
I would like to display "Terms and conditions" when user trying to create a new post. Users should Click "I agree" link and then proceed to create a new post(wp-admin/post-new.php).
Is there any good plugin available for this? Or can anyone give me some snippets? Looking forward to it. Thanks | Yes there is: Terms Of Use plugin.
Also able to add the checkbox to signup pages, works with Formidable forms plugin and enables you to add the checkbox before viewing a (front- or backend) page. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins, multisite, wp admin, terms"
} |
Styling child custom menu pages
I have a custom menu created using Appearance > Menus which contains top level and child pages.
I would like to be able to indent my child level pages to give some sort of visual hierarchy to the content.
What is the best way to achieve this? | Some digging around led me to find that all the items were marked up with the class `sub-menu` which I was able to style in the CSS. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "menus, css"
} |
Styling issue with custom menus and sub menus
In a previous question I asked (and later worked out) how to style sub menus, I want to expand on that with another question related to styling sub-menus.
I have hit an issue were if the parent is the selected page all child pages pick up the same styling, I believe this is because the `current-menu-item` class gets added to the parent li.
If a child element is selected only the child is highlighted (which is correct)
Has anyone encountered this before? What is the best way to only have the selected page highlighted and not the child elements of that page?
As requested, here is the CSS that is being called to highlight the child menu.
.current-page a, .current-menu-item a {
background-color: #EE8833;
} | You can try using the .current-menu-item li a"first-child selector. Here is an example I've used in the past to highlight the current menu item only:
#menu .current-menu-item {
background:white;
}
#menu .current-menu-item li a:first-child {
color:white!important;
}
#menu .current-menu-item a {
color:black !important ;
}
You will need to change the #menu to your id or class. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "menus, css"
} |
Ways to show multiple, separate galleries per post?
I'm working on a project that will require two separate galleries to be displayed on the same post. One gallery is specific to the product and the other is professional generic shots. The content of both galleries will change with every post.
I need to figure out how to show two separate galleries on a post and repeat this process daily.
The only way that I can think of is to store images in another post (post-b) and insert post-b using either @MikeSchinkel's or @Scribu's post to post connector.
What would you do? | If possibile, use NextGen Gallery plugin, to manage the gallery, and with the help of custom fields, manage it in the post
You can create two custom fields, like:
1. first_gallery
2. second_gallery
and fill it with the nextgen gallery ID. You can do a custom metabox with a select box, if you want.
The in the frontend code, use
$first = get_post_meta($post->ID, 'first_gallery',true);
$second = get_post_meta($post->ID, 'second_gallery',true);
...
echo do_shortcode('[nggallery id='.$first.']');
echo do_shortcode('[nggallery id='.$second.']');
...
Hope this it helps.
**Bonus** : there are many nextgen gallery plugins that let you change how the gallery is rendered to the user. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "images, gallery"
} |
How do I change the web site summary in search results?
I have a web site that I am working on, hendersonvillecameraclub.org. When I use Google to search for the site using 'hendersonville camera club' as the search terms my site is the 6th result. Below the page title, it gives a snippet of the most recent post on the site. My question is, how do I change what information is displayed in the summary? I would prefer to put some static text there that provides a better description of the site.
This site is hosted by GoDaddy, not sure if that's relevant information.
Thanks! | Try an SEO or meta tag plugin that will give you the most options to work with meta for the home page, for post pages, static pages, etc. It's not enough to simply add one metatag to the header template.
| stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "search engines"
} |
Can Wordpress plugins "Talk to each other"?
Sorry if this is a really silly question, but I am very new to Word Press.
My question is, can one plugin update the settings of another Wordpress plugin? I suppose this might depend on the plugin and where it stores its settings. I don't know if plugins store their settings in static files or in the database. | Simple Answer would be yes.
It really depends on the plugin. A good plugin will take use of the many API's that Wordpress has set up for development, such as the settings API. Most plugins will probably store their settings using get_option.
A good place to start will be the Wordpress Codex | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "plugins, plugin development"
} |
What's the most efficient database method to add and query usermeta?
What's the most efficient way - concerning the database - to add and query extra usermeta fields to a profile?
I need to add four additional fields of numeric and text data to a user profile and then query that to compile the data for display in a template. And there are potentially thousands of users.
There are lots of examples to store the data in usermeta. But should this amount of data be stored in the usermeta table?
Or should I store it all in a new database table? And if so, how do I initialize a new table and then write to it? | > There are lots of examples to store the data in usermeta. But should this amount of data be stored in the usermeta table?
I don't see any reason why you should not use the default user meta data table, after-all that is what it is for, regardless of the amount of users/fields.
The user meta function , such as `get user meta` uses `get_metadata` with the `$meta_type` object set to user. <
If you want to mess around with new tables you can use the `$wpdb` class and create a new one, this post covers how, < .
There is also a plugin called Pods CMS that allows for the creation of custom database tables for content types, but unless you have a specific reason for doing so, just use the built in user meta tables. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "database, user meta"
} |
Dynamic height in custom header image panel
I've enabled the custom header image panel for my theme.. That all works fine, but it has a predetermined height. How can i make it dynamic? The width can be permanent.
I used this code. <
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'yourtheme_header_image_width', 940 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'yourtheme_header_image_height', 198 ) );
set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); | Since you are using `apply_filters` you can use `yourtheme_header_image_height` filter hook to change the height:
add_filter('yourtheme_header_image_height','dynamic_height');
function dynamic_height($height){
$custom_height = get_option('dynamic_header_height');
return $custom_height;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "headers"
} |
Where are a theme's options stored and can I export them to be imported into freshly installed themes?
Imagine that a person has a few premium themes that they use for clients. In those premium themes are many different options that can be set. Is it possible to set the theme's options to the most common and preferred choices and then export those options for later importation into other fresh WordPress installs with the same theme? That way one is not merely pointing and clicking their way through the various options over and over again for each new install. | The answer is theme depended and since most premium themes have their own framework/options panels then its going to be hard to tell where are the options are saved but in most cases they are saved in the options table in the database.
So the tricky part is to know what are the options names. You can look for them in the themes code either by searching for `add_option` , `update_option` and `register_settings`.
e.g. `grep -rnw 'wp-content/themes/' -e 'update_option'` to search from the command line. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 4,
"tags": "theme options, configuration"
} |
How can I get dynamic content on my static home page
Sorry for this but I am sure this is a duplicate question, but I have been searching, but I cannot find a suitable answer for this question. I hope you still can help.
I want to create a website with a few static pages, and a blog. Now on one of the static pages, the portfolio page, I want to have all of my work in boxes in a list. Just like you would have blog posts.
Now I not want to create a post for each of the work I have done, because it will mingle with the blog I guess. Is there another option on WP to have snippets of content, just as posts, which could be loaded into a page.
Or should I just create the whole portfolio page just as a big static page. | You have to create Custom Post Type, I've done it for the very first time using this tutorial.
Basically, you have to add "a few" lines to functions.php and then add your portfolio items as posts in new custom post type (it will be available in your admin panel).
I hope it helps :) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme development"
} |
get a list of posts from Custom Taxonomy
I can get a category id or slug for my custom taxonomy just fine, but I then need to be able to get all the posts as an array for that taxonomy entry. My code is as follows:
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
endwhile;
When I add 'category_name'=>'my_taxonomy_name' to the args array, it just causes the $the_query to be empty although I know that there is post in there. I have also tried changing it to 'cat'=>22, but this also has the same fault.
Can anyone help?
Cheers John | Check out the Taxonomy Parameters.
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'taxonomy_name',
'field' => 'id',
'terms' => '22'
)
)
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
//content
endwhile;
?> | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "custom post types, custom taxonomy"
} |
How do I customize the positioning of Wordpress widgets?
I want to create new sidebars, footers, etc. where I'll be able to move widgets. Can I try just try to edit the main CSS file to accomplish this or is it more complicated? | Linda, I actually answered a question very similar to this earlier today. See the following:
Display specific widgets in different area's around the page
It's not overly difficult, and opens up a lot of possibilities. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "widgets"
} |
How to change a meta value (of a published post) after X days.?
I have a custom field. I would like to change the text of that custom field after x days.
I want something like this:
if ( published post is more than 90 days old ) {
echo "your post is more than 90 days old";
}
else {
echo "your post is less than 90 days old";
}
Can anyone help me to achieve this?
Thanks. | You shouldn't need to use a meta field for this logic.
In the loop `$post->post_date` holds when the post is published. From there you can determine if the date is 90 days old:
$datetime = strtotime($post->post_date);
if( $datetime < ( time() - ( 60 * 60 * 24 * 90 ) ) ) {
echo "> 90 days old"
} else {
echo "< 90 days old"
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "functions, wp admin, metabox, date time"
} |
How to Display Wordpress Plugins in Normal Website (Without Wordpress)?
Probably it can by reverse engineering, but is there any easier way of doing this? | Quite simply put there is no easy way to make a plugin that's made for WordPress to work without WordPress.
The amount of effort to convert a plugin is dependant on the complexity of the plugin and on how much it integrates with WordPress.
Most plugins will make use of native WP functions, DB tables, hooks and filters. There is a lot there that you would have to consider.
Either way you look at it any plugin to make it work standalone would require a lot of time coding, to be honest I just wouldn't bother.
You would be better finding scripts that work standalone and do the functions you are after or build one from scratch for your needs. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 1,
"tags": "plugins"
} |
.current-menu-item class on custom post type children pages - again?
There is the situation. I have created the custom post type - products withfuncionality like pages - I have to create hierarchy.
f.e:
1. Chairs:
* Oak Chair
* Nice Chair
The weird thing happens with wp_nav_menu(). When I open the first level page Chairs and display all the Chairs childrens in theme, the nav menu for the li item Products, gets the .current-menu-item class, but when I open the child page f.e. Oak Chair, the class disapears.
Why is that and how to set .current-menu-item class also when child page is opened?
This same problem happens again :( WP Version 3.2.1
the ancestor-class .current-products-ancestor is not setted up :( | Use this selector:
.current-products-ancestor
... to change the styles on that menu. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 2,
"tags": "posts, customization"
} |
Adding more text to a post, after it was published
I'm trying to build a wp plugin, which will basically add some text for every post, in the post itself, I'm afraid that the codex is too large for me to even know what to look for, so I'd appreciate if someone could point me in the right direction.
Edit: As per request, the info should be added to the post's text on the database, at the end of the post, it's not static, it's a random embed from a tube site, based on a query I run on the tubesite. | Your best bet is to use the `the_content` filter hook and add your content to the post "on the fly" for ex:
add_filter('the_content','add_my_extra_content');
function add_my_extra_content($content){
$my_extra = "<h5>this is the extra content</h5>';
//add before post content
// return $my_extra.$content;
//add after post content
return $content.$my_extra.;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin development"
} |
Display product SKU on page with Jigoshop
I'm using the Jigoshop plugin (everything's going great so far!) and need to display the product SKU on a page, does anyone know how to do this?
p.s I would ask on the Jigoshop forum but you have to pay for it. | In the loop-shop.php you can just add this:
SKU: <?php echo $_product->sku; ?> | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "e commerce"
} |
How to approach displaying products with no shopping cart plugin or post type?
I want to show products like an eCommerce store with product categories and detail pages, but I have no need for a shopping cart or checkout system. This is just to display the products for informational purposes.
I have used custom post types on another project and that worked out fine, but I am wondering if anyone knows of a plugin that would make this fast and easy to customize. Also an import/export feature would be nice for adding lots of products. | if you have no need for regular blog posts, you can just use those. the post is probably not overly different from a custom post type for a product. though i just did a CPT for products and added some cool features. though since they were related to metaboxes and custom columns there's no reason you couldn't add them to posts, but in case you want to use your blog ever, i'd probably keep them as a separate CPT.
the ecommerce plugins i've seen are usually related to setting up your shopping cart.
where do you want to import from? you can always import/export your posts w/ the xml built-in import/exporter | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins"
} |
How to update post's featured image in front-end
I created a new template page with code to allow front-end posting. Everything works great, with tags, post meta and image uploading (as featured image).
I have seen many codes about front-end post editing, but even though I tried to figure it out I can not successfully make it to work.
I took as example this How can I edit a post from the frontend? and placed it in single.php with no luck. I guess the right way to have it, is to have an EDIT link below the post and there will be appear a new php template that contains the edit form when it is clicked. Is this correct?
Secondly, how can I update the featured image I added from the front-end ?
Thank you for your help. | The Front-end Editor plugin allows you to change post thumbnails (featured images). | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "front end"
} |
Is it possible to display my theme sidebar in wordpress admin?
I'm trying to create sidebar in my wordpress admin. This is because I'm trying to make my wordpress admin look like my front end.
My front end theme has sidebar in the right side. So i would like to display the same sidebar in my admin area.
I know its possible by editing wordpress core files. But if i update my wordpress core in the future then all my works will be wasted.
So i'm trying to find some alternate ways. Is there any wordpress admin hook available out there to edit admin body, like editing admin header(admin_head) ?
I respect and appreciate everyone's comments/answers. So please help me. Thanks to all | It's a bad idea to try to make the wp-admin area look like the front-end. It's an uphill battle.
Try using my Front-end Editor plugin: it allows editing widgets directly from the front-end etc. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp admin, sidebar"
} |
Plugin access and Roles
I'm new to Wordpress and am a little confused with which Wordpress user types can access plugin functionality?
As administator I know I can activate (and deactivate) plugins. I can access their settings through the dashboard. However, this doesn't seem to be the case for the editor user.
Which plugins settings (if any) are editable for an editor?
The reason for me asking is because I want to manage my clients sites, but there may be some plugin settings that I will want my clients to use. I am assuming that the best way of working will be me as administrator and my clients as editors. | By default only super admins/administrators can edit plugin/theme settings. <
If you want to give access to plugin/theme settings (or other stuff) for an editor you can add a capability to a role. How can I allow the Editor Role to change Theme Settings? | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, user roles"
} |
Want to add a custom author link to a single.php
I want to add a custom link to linkedin near author name. It should be very easy if it would be only one author, but now it's not. So, I have to add something on all single.php and somewhere the real links. Can anybody help me with this? Thanks! | Have a look at this tutorial. It will teach you how to add a linkedin box to a user's profile and how to display that in a post. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "author"
} |
Get current page id, title, url, etc
Sorry but I get lost on Wordpress's codex. I am trying to add a mail this page sharing link and want to include some info from the page. In pseudo code is this possible?
`<a href="mailto:?subject=".CURRENT_BLOG_NAME." ".CURRENT_PAGE_TITLE."&body="intro%20text%20".WP_PLUGIN_URL.$_SERVER['REQUEST_URI'].">Mail to a friend</a>`
Where `CURRENT_BLOG_NAME` is ??? and `CURRENT_PAGE_TITLE` is ???
`WP_PLUGIN_URL.$_SERVER['REQUEST_URI']` **does** get me the path to the current page. | <?php
$link = 'mailto:?subject='. get_bloginfo() .' '. the_title_attribute(array('echo'=>0));
$link .= '&body=some text '. get_permalink();
?>
<a href="<?php echo $link ?>">mail to a friend</a> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "variables, globals"
} |
Site blocked by WebSense on fresh WP Install
Just put up a new WP 3.2.1 install running twenty eleven, with one post "coming soon". I haven't yet begun developing the site. At my place of business, it is currently blocked by WebSense as "potentially damaging content", yet I was able to access the site yesterday.
Does it appear as if my site is hacked or has spam links, or does the web filter just not like my newfound sense of freedom? :)
The site is here, I can't currently check into it due to the whole web filter issue. It does look fine on my iPhone, but I can't view source.
**Theme** : Twenty Eleven (no modifications)
**Plugins** : Remove Double Space | Websense blocks based on URLs, not on site content.
You can use their Site Lookup tool to have it fixed: <
You'll have to register with their site. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "installation, theme twenty eleven, hacked"
} |
Paypal buttons disappear in the text editor
I have a series of paypal buttons on a web page that I am trying to migrate from another site onto Wordpress.
When I copy the html and paste it into the (HTML TAB) of the wordpress editor, I can see the buttons. But when I press save the code disappears... | Elements like these (PayPal buttons), _should not_ be inserted as page content in the editor, but in your WordPress template files.
I assume you are developing your own WordPress theme! If not, you can modify an existing shipped WordPress theme such as the _Twenty Eleven_ WordPress theme.
Depending on the placement of the button, you should do it in `header.php`, `sidebar.php` or `footer.php`, all, of your selected WordPress theme. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "paypal"
} |
How do I add content to the dashboard in Wordpress?
I have created some content using php, js and html which shows the bandwidth the site has used (using the cPanel API and the Google Graphs API) I want this to be shown on the dashboard in Wordpress (viewable to Admins and Editors only)
How do I do this? | <?php
/*
Plugin Name: Dashboard Google Page Rank
Plugin URI:
Description: Shows your google pagerank in the wordpress dashboard
Author: Weston Deboer
Version: 1.1
Author URI:
*/
function gpr_wp_dashboard_test() {
include('yourfile.php');
}
function gpr_wp_dashboard_setup() {
wp_add_dashboard_widget( 'gpr_wp_dashboard_test', __( 'Google Page Rank' ),'gpr_wp_dashboard_test');
}
add_action('wp_dashboard_setup', 'gpr_wp_dashboard_setup');
?>
I have made a small modification to the above plugin. But all you should need to do is include your file which displays the data and it should show your widget in the admin dashboard. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "plugins, dashboard"
} |
Can I add/replace the Wordpress image in the Dashboard
Is it possible to change the Wordpress logo and header in the Dashboard so I can customise it a little more to my business? Ideally it could be done in a way so that it wouldn't break every time I upgrade Wordpress to the latest version. | baritoneuk - There are several plugin which can handle the branding as well as code which removes the need for the plugin.
For a plugin, I recommend White Label CMS, if you're feeling adventurous try this article from WP Beginner | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "customization, dashboard"
} |
Is there a function to get post info for any publish_status by post ID?
I'm trying to, essentially, check whether a post exists and if it does (in published, draft or auto-draft states) return the post info. I'm finding `get_post()` doesn't seem to work with drafts, and `get_posts()` doesn't allow me to specify the specific post ID I'm looking for.
Is there a function to get post info for any `publish_status` by post ID? | There is nothing in the codex that would suggest that `get_post()` would not work with drafts. if you experience otherwise, try `get_posts()` with the `include` or `post__in` parameter.
Also see the supported type and status parameters here. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, wp query, database"
} |
Is there a way to enable bulk edit and quick edit on custom post types?
When viewing a list of all standard post or pages there are convient quick edit and bulk edit functions to edit author, template, status, dates, etc...
Is there an easy to enable similar quick edit and bulk edit tools on Custom Post types?
For example going to: ../wp-admin/edit.php?post_type=page select all checkboxes, select edit from drop down, click apply, you get options for Author, Parent, Template, Comments, Status, but none of those show up for ../wp-admin/edit.php?post_type=mycustomposttype | Make sure that `show_ui` and `show_in_menu` are set to `true` when the post type is enabled. then all the usual post/pages features will be available.
See: <
Also, make sure that those features are explicitly declared as by the **CPT** as supported. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, post editor, bulk, quick edit"
} |
Return comments_link() instead of echoing it
Is there a way to return the comments link instead of echoing it? I've been searching the Codex for a little while now, without being able to find a function that just returns the link and doesn't echo it.
Thanks. | Use get_comments_link(), it retrieve the link without echoing it.
This is the function that is used by `comments_link()`.
See also: < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "comments"
} |
Are Custom Taxonomy Templates Possible?
I am trying to have some information specific to a taxonomy term appear above that taxonomy's archive list.
Example: Taxonomy is 'Sports', with football, soccer, and baseball being terms within the 'Sports' taxonomy. I would like to have a small description of each sport display above that term's archive page.
In researching this possibility, I have read the Category Templates page, found a plugin that appears to do what I want, but only with regard to Categories and not custom taxonomies.
I would do it with Categories, but I have multiple taxonomies now and cannot use the simple categories solution any longer :(
Am I being dense, or are custom taxonomy templates not possible? | Custom Taxonomy templates are entirely possible, the order of the template loading is,
1. `taxonomy-{sometax}-{someterm}.php` \- If the taxonomy were sometax, and taxonomy's slug were someterm
2. `taxonomy-{sometax}.php` \- If the taxonomy were sometax.
3. `taxonomy.php`
4. `archive.php`
5. `index.php`
This template hierarchy give you tons of control on how you want to alter the display of taxonomies as a whole, as a group or alone. <
For example in your case you can create a template called `taxonomy-sports.php` and then customize it however you want using conditionals, template tags and functions. | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 2,
"tags": "categories, custom taxonomy, archives"
} |
Tag subscription option in wordpress. How?
I love stackexchange's tag subscription feature. Now i'm receiving email notifications only for the topics i'm interested in. I would like to have this feature in my wordpress site. Is there any good tag subscription plugin available?.
If there is no plugin available why not WA experts create one and submit it in the WPSE Plugin Repository? | If you're willing to use an outside provider, you can add the tag feed to Feedburner.
First get the tag feed:
Then to to feedburner.com and create a feed, then enable "Email Subscriptions" (under the "Publicize" tab).
I've done this, and it works well. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "tags, email, notifications, subscription"
} |
Allow Author role to publish one post type and not another
I have two custom post types. One of them, I would like the author role to be able to publish. The other one, I would like for them to "Submit for Review". Any suggestions? | When the post type is registered, <
one can specify custom 'capabilities'. eg I have an events post type, with event as a base for the capabilities, so automatically, there is a matching set like the page/post capabilties.
Then one can use justin tadlock's members plugin to assign capabilities to roles. Assign 'create' but not 'publish' to the 'review' post type, but full rights to the other type.
Simple. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, permissions"
} |
Sell "create a post", paid account for post creation
How can in wordpress, one sell the "create post" option
To elaborate more. One has to pay an amount before he can make create a post on the wordpress site.
MORE ELABORATION
Suppose a person pays $20, he gets to write a post on wordpress. This is just like a paid listing website. If the person wants to create another post, he has to pay another 20 Bucks. | As per comments you can make use of user meta functions to store user-specific information and use capabilities (or some more simple check) to control if user can create a post. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "plugins, posts, e commerce"
} |
wp_signon( $creds, false ); not working
In my multisite i'm using a custom blog registration using : `wpmu_signup_blog($domain, $path, $blog_title, $user_name, $user_email, $meta);` and the site creation is successfull.
and i want users automatically sign into their site admin panel on signup,for that i use :
$creds = array();
$creds['user_login'] = $_POST['username'];
$creds['user_password'] = $_POST['password'];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
echo $user->get_error_message();
But this will return an error :
_ERROR: The password you entered for the username mysite is incorrect. Lost your password?_
i need auto signin without using a plugin!!!
Please help... | Hope this helps someone else. After hours of debugging, I found out that under multisite setup, wp_signon ($creds, false) will not log you in. So you should either do:
$user = wp_signon ($creds, false);
wp_set_auth_cookie($user->ID);
or
$user = wp_signon ($creds, true); | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "multisite"
} |
Wordpress automatically adds <pre> tags when pasting code, how to stop it?
I am presently learning PHP and Linux simultaneously. And I want to blog my notes not only for my future reference, but also because it could help others.
I just noticed an issue with Wordpress - - it automatically adds `<pre></pre>` tags in the background (HTML-side I mean, in the visual editor I see the code's background highlighted) as soon as I paste some code, be it HTML, PHP etc.
I have searched a lot, and could find nothing about this. Looks like nobody thinks this as an issue, or it's something too easy to resolve. Either way, I am on the other side of things. So, please help me out.
I want Wordpress to stop highlighting the code like that. I Just want it to keep whatever I paste as it is. | The only way to keep it the way you paste it is by switching to the HTML tab - this will show you the raw code as you formatted it. Wrapping code in tags is also a good idea because it tells the browser that the code is literally 'precomposed', and it therefore won't render it. In terms of WP actually altering your code it is likely it will change characters such as '<' for their HTML entity equivalent, meaning browsers will render it as text rather than code.
Why exactly do you want to keep it without the tags? It shouldn't alter that much. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "php, html, pre"
} |
Customize the upload screen
I would need to simplify the "upload new image" interface for our Authors : basically, hide a few fields that will only confuse my wordpress "authors" (like the "Description" and "Alt" text inputs). Administrators and Editors need to see these, though.
How can i implement that hiding/showing inputs according to the user's priviledges? | You will need to hook into `attachment_fields_to_edit` and unset them for a role.
You can use `current_user_can('author')` <
Example to remove image alt field
function remove_caption($form_fields) {
if (current_user_can('author')){
$form_fields['image_alt']['input'] = 'hidden';
return $form_fields;
}}
add_filter('attachment_fields_to_edit','remove_caption', 15, 2);
My initial post used `unset` but I tried it and it did not work, from the example in this post: How can I remove fields in the attachment editor? , not sure why, instead the example above works using `hidden`. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "admin, user roles, uploads"
} |
determine if specific page is in list?
It's not hard i think, but i run out of ideas...
In template file I have code like this;
$current = $post->ID;
$parent = $post->post_parent;
$pages = get_pages('child_of='.$parent.'&parent='.$parent.'&sort_column=post_title&title_li&hierarchical=0');
$front_id = get_option('page_on_front');
I cant figure out how will statement to determine if `$front_id` is in `$pages` array look like !
thx for Your time! | If you just need to remove, or ignore, it from `$pages`, use the `exclude` argument instead;
$pages = wp_list_pages( array(
'exclude' => get_option( 'page_on_front' ),
'child_of' => $parent,
'parent' => $parent,
'sort_column' => 'post_title',
'title_li' => '',
'hierarchical' => '0'
) );
I've used `wp_list_pages` as I assume this is the function you've intended to use (`get_pages` does not have a `title_li` argument).
If that **isn't** what you were after, then just loop over the pages to determine if it's there;
foreach ( $pages as $page ) {
if ( $front_is_here = ( $page->ID == $front_id ) )
break;
}
if ( $front_is_here ) {
// front page is among pages
} else {
// front page is *not* among pages
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "navigation"
} |
Localize Plugin Description
Currently i'm working on a simple WordPress Plugin.
I know within the Plugin i need to write my strings as `__()` or `_e()` and call `load_plugin_textdomain()` but i wonder how to localize the Plugin Description.
Example:
!example
_This is not the Plugin i'm working on. It's just an example to show what i mean._ | Add two extra headers:
Text Domain: your-text-domain
Domain Path: /languages
Then use the plugin Codestyling Localization to create your language files. Usually it'll find the description. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "plugins, plugin development"
} |
cannot drag and drop widgets since wordpress 3.2.1
I recently updated my site to wordpress 3.2.1 automatically.
Now I tried to manage my sidebar widgets, and noticed I can no longer drag and drop the widgets around. If I look into my browser-console, I notice that the page is unable to load jQuery. Weird: it appends my root-url to the jquery-url, like so:
<script type="text/javascript" src="
So it is normal that it is not found. How can I fix this. Is there something wrong in my configuration? Or is this a bug? Then it should be general, for everybody, no? | Your theme may be written badly and replace the correct jQuery. Switch to TwentyEleven to check for this. If this doesn’t help, turn off all plugins and re-enable them step by step. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 1,
"tags": "widgets, jquery"
} |
How to validate this deprecated function
I want to validate this deprecated function:
add_filter('user_has_cap', array(&$this, 'filter_user_has_cap'), 10, 3);
It needs to use roles or capatibilies, so I guess 10 is the admin level, so I could use "edit_pages":
add_filter('user_has_cap', array(&$this, 'filter_user_has_cap'), 'edit_pages', 3);
But what is argument "3"?
Thank you Oliver | First of all, it's not the add_filter() call that you're supposed to be modifying, but the callback: 'filter_user_has_cap', i.e. go to where that method is defined and change the user level to 'edit_pages'.
Fixing deprecated notices is easier with the Log Deprecated Notices plugin. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "functions"
} |
Moving wp-config.php: Can this be done after site launch?
For additional security, the suggestion is made to move the wp-config.php up one level. Can this be done after the site has already been launched? Any potential issues in doing this? Are there an restrictions/suggestions on what the new folder should be called? | You can safely move it as far as I know.... but what do you mean folder?
Up one level would already be a folder....
if your site is in html, or public_html or whatever, you place the wp-config file in whatever folder holds your html or public_html folder
like if your path is /home/content/u/s/e/user/html/
And your WP is in html, the wp-config would go in user, the next folder up which is not web accessible. WP will automatically look for it there
If you are on shared hosting, you probably can't do that anyway
And if you have WP in a subdirectory, there would be no point in moving wp-config, as moving it up a level would still put it in a web accessible directory | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 5,
"tags": "security"
} |
How do I add a class to <body> that is generated by <?php body_class(); ?>>
I need to add a class of "two-sidebars" to the regular bunch of WP classes that are generated by `<?php body_class(); ?>>`
The reason I need to do this is I'm integrating WP into a Drupal install, and need to keep the "two-sidebars" class for style reasons for the Drupal part of the page.
What's the best way? jQuery? Is it possible to hook into body_class? | You can add to the function simply by placing the desired class as the first parameter like so `body_class('class-name')`.
If you'd like a little more flexibility you can hook into it using `add_filter('body_class','my_class_names')`.
You can read more here. | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 2,
"tags": "css"
} |
Mixing Tweets with Posts
I have a client who wants their blog to display both Posts and Tweets in chronological order. These should be mixed into the same feed. I didn't find any plugins that accomplished this, although there may be one I missed which someone could recommend.
I was thinking to pull the tweets and store them as a custom post type, and then just pull both post types when displaying, but Twitter's TOS does not allow the storing of the data.
Only option I see is to pull the tweets on page load, and then write a custom function to merge the two chronologically, which seems like a bit of work. Also, as far a caching the tweets, how can I go about this, considering that Twitter does not allow for storage of this information?
Does anyone have a recommendation on the best way to accomplish this? Also the most efficient?
Thanks in advanced. | I've done this with Twitter Tools. Basically it hooks up the blog to a Twitter feed, and for each new tweet creates a blog post. You can put twitter posts in a separate category (or add tags), and use that to style twitter-posts differently from regular posts, hide the comments field, whatever.
Hope this helps - good luck! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "posts, cache, twitter"
} |
Printing out Main Category ID's in a Loop
I'm looking to print out All of the Main Categories (So Exclude Sub-Categories) in a Loop, I need to get the ID's to do some advanced category listings.
So I need to echo this out:
3 CatName
4 CatName
5 CatName
x CatName
Where the number is the category # and the CatName is the name of the category | <
example:
<?php
foreach(get_categories('parent=0&orderby=id') as $cat) {
echo $cat->term_id.' '.$cat->name.'<br/>';
}
?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "categories"
} |
Web App mode leaves users stranded when following image links when using WPTouch with W3 Total Cache
In most of the posts on my site, embedded images link to the actual image file. I'm also using Web-App mode via WPTouch. In web-app mode images linked to their larger versions shouldn't open; since Web-App mode has no back button, a user can follow a link to a image and become "stranded" there.
I'm also using W3 Total Cache, which appends the param string "?9d7bd4" to all my images. This makes sure that if you change your browser cache policies all users immediately see that change.
However, apparently the the appended image string allows for the images to be clicked on and stranded. Interferes with whatever is stripping the image links.
All BraveNewCode can tell me is try "disabling Browser Cache in W3TC" which I obviously I'm not interested in doing. Suggestions? | Best way to avoid this is to go to "Browser Cache" and uncheck "Prevent caching of objects after settings change" under "Media and Other Files" | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "images, plugin w3 total cache, mobile, plugin wptouch"
} |
How to empty debug.log when file size is above xyMB?
Sometimes I forget to empty my debug.log file (or that it exists) and after trying to get around a bug, I find it having simply too much content to open it in ex. the basic Windows Text Editor.
Part of my wp-config.php file:
error_reporting( E_ALL );
define( 'WP_DEBUG', true );
define( 'SAVEQUERIES', true );
define( 'WP_DEBUG_LOG', true ); // file: /core_root/wp-content/debug.log
define( 'WP_DEBUG_DISPLAY', true );
**Question:** Is there a way to do this via Wordpress, or do I have to do it with basic php functions? | Create a cron job for a function which checks the file size and runs `unlink( WP_CONTENT_DIR . '/debug.log' )` if necessary. | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 2,
"tags": "debug"
} |
Comments on homepage (index.php) are duplicated under posts
I am displaying WP comments on homepage in my index.php file, but the problem I have is that some comments are displayed under each post. The comment number is okay, but the comments are assigned wrong to the post. However when displaying the single page, everything is okay.
I checked the IDs of the comments in the DB and it seems to be okay too.
Any ideas what's going on?
I am using the following code in my index.php to display the comments:
<?php global $withcomments; $withcomments = 1; comments_template(); ?>
Here is the whole index.php and if it helps here is the actual page.
See for example the comment on the latest post from "Linda Walker", it is displayed under each post :-/
P.S. The posts were originally imported from MovableType, I hope it has nothing with that as I used the official import plugin. | Seems I fixed it myself, I had to call
<?php global $withcomments; $withcomments = 1; comments_template('/comments.php', true); ?>
as I am filtering comments by type:
<?php wp_list_comments('type=comment&callback=jennygg_comment'); ?> | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "comments, homepage"
} |
Wordpress keeps truncating my feeds and I can't stop it
I have a little problem with my self hosted wordpress blog.
the problem is it keeps truncating my feeds even when I have chosen not to in the settings page.
one thing to bear in mind is that I use `<!--more-->` tag in almost all of my posts. I was wondering if it's because of that or something else?!
any help would be awesome.
thanks | Make sure you check the page source of your feed - some browsers will not show the full feed when looking at it raw (as the plain XML file) when using your browser to view <
If you look at the raw source the full text should be found in under the "content" tag - Firefox for example will only show the "title" "link" and "description" but hide the content. IE will show the full feed in the browser.
Also make sure the full feed is set in the wordpress settings | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "rss, feed"
} |
Which page is referring to *all posts by author*?
I am developing a blog and whenever I press on an author name I get the page with all pages by this author, but this page looks really bad.
Any ideas of where I should inspect for problem? | please refer to the codex: <
however, your problem is caused by a conflict of the `.author` class output by the `body_class()` and this existing style in custom.css:
.author {
float: left;
margin-top: -3px;
width: 219px;
background: #E7ECEF;
border-right: 1px solid #D6DFDC;
height: 41px;
cursor: pointer;
}
check why this style is added there in the first place; if there is no reason, remove it; if there is a good reason, try to change it to:
#content .author { ...... | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "template hierarchy, author template"
} |
How to pass the Querystring in pages?
I can easily add menu in the admin panel menus.just select the pages and cretae menu. i need to set pages URL with querystring. is that possible?.
for example,
< for this url i need to set <
how can i set this querystring value using menu?.
thanks Ravi | You can create a "custom link" for those pages where you need to add a querystring. Have you tried that? Best of luck! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "pages"
} |
Can I access a post meta field before the loop?
If I call the following function (on a page template, e.g. page-home.php) before the loop, nothing is returned. If I call it during or after the loop, the expected values are returned. Is there a way to access these meta fields before the loop runs?
function home_content() {
global $post;
$headline = get_post_meta($post->ID, 'top-headline', true);
$body = get_post_meta($post->ID, 'top-body', true);
$return = '<h4>' . $headline . '</h4>';
$return .= '<p>' . $body . '</p>';
echo $return;
} | You can get it by calling global $wp_query and assigning post->ID to a variable.
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'top-headline', true);
?> | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 0,
"tags": "custom field, loop, post meta"
} |
Add meta data to the custom post type ARCHIVES page
i can make an easy template for displaying custom post types. but what i'd like to do is add some editable text to the top of my loop.
for example:
Hey wow, we really make cool products. I think it'd be nice if this text wasn't had coded into the template. any ideas?
product 1
product 2
product 3
and so on.
what is the easiest way to do that? is it possible to attach meta to a post "type"? i know you can sort of do something like that for categories/tags/tax, etc. but for a "type"? should i make it a theme option? would i be better served by making a post type and then displaying it through a taxonomy?
i do want the resulting permalink to be mysite.com/products | I believe wp_options is the best solution for this. It's easily editable in an theme option page, but still you must hand code a new option each time you register a new Custom Post Type.You can use these
* get_option
* update_option
* Creating Options Page | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, custom post type archives"
} |
Fatal error: Call to undefined function wp() in ../wp-blog-header.php?
> Fatal error: Call to undefined function wp() in /home/content/33/7211533/html/someSite/wp-blog-header.php on line 14
Can anyone figure whats the problem?
I already update the `wp-includes` and `wp-admin` folder and my `functions.php` is fine, but I haven't figure out how to fix it. Any suggestions?
* * *
**EDIT**
I reinstalled WordPress, (upload the new copy on the site, and I made sure it's up to date) - equivalent to a manual update.
After that its started to work fine, so this problem is now fixed. | `wp()` is quite essential function. It resides in `functions.php` file (don't confuse with `functions.php` in theme, different thing) and I don't think you can load WP without passing `require` directive for that file at some point.
So your install seems very broken - either `functions.php` file in core is damaged or something else is broken and makes it skip loading that file. | stackexchange-wordpress | {
"answer_score": 9,
"question_score": 13,
"tags": "fatal error"
} |
Moving my current wordpress blog to a subdomain
I currently have a blog set up on my domain (eg domain.com), but I would like to move it and all of its contents to a subdomain (eg sub.domain.com). Is there anything I need to watch out for or modify? Is there a tool which might do this more easily?
I'm afraid of database issues (it will be using the database instance as it is now) or calls from within the blog itself not resolving. | Check out this word-press plugin: Backup and Move.
> Backup And Move plugin allow blog administrators to create a complete backup of their blog and easy option for restore it on a different server, domain, location, etc. This plugin can make all the transitions of moving a wordpress blog , creating a complete backup and restoring a previous backup very simple and smooth. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "blog, domain, server"
} |
Custom Post Type sorted by Title
I created a non-hierarchical custom post type and, by default, it's sorted by date published.
I know I can reorder them by Title with `query_posts()` in the archive template:
global $query_string;
query_posts( $query_string . '&orderby=title&order=ASC' );
but it takes another SQL query on each archive page. Is there a way to register the sort order natively, eventually to get posts sorted by title even in the admin? | Try...
add_filter("posts_orderby", "my_orderby_filter", 10, 2);
function my_orderby_filter($orderby, &$query){
global $wpdb;
//figure out whether you want to change the order
if (get_query_var("post_type") == "my_post_type") {
return "$wpdb->posts.post_title ASC";
}
return $orderby;
} | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "custom post types, query posts, sort"
} |
Can't pass table to $wpdb->prepare
I'm having trouble passing a table variable to $wpdb->prepare(); Here is functioning code:
$table = $wpdb->get_blog_prefix( $blog_id ) . 'my_table';
$voters = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE user_id= %d AND post_id = %d;", $user_ID, $post->ID ));
This works great. However I think I should also be including my table in the prepare statement. But, it breaks when I change it to this:
$table = $wpdb->get_blog_prefix( $blog_id ) . 'my_table';
$voters = $wpdb->get_row($wpdb->prepare("SELECT * FROM %s WHERE user_id= %d AND post_id = %d;", $table, $user_ID, $post->ID ));
Any ideas on why it might be breaking? | The prepare() method escapes %s. The second piece of code you listed breaks because quotation marks are added to the table name, hence it doesn't match what's in the DB.
The first piece of code works because it's a straight string replacement hence matching the name of the table in the database.
What is the error message you are getting?
HTH | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "query, query string, wpdb, table"
} |
How to include jquery-ui library in WordPress?
I'm trying to load the jQuery UI library into a WordPress plugin using this enqueue statement:
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
The jQuery library loads fine, but the ui-core is MIA. The only way I can get ui-core functions to fire is to load the library with a static include like this:
<script type="text/javascript" src="
What am I missing? | jquery is enqueued by default on admin side. So, it may not be loading due to your `wp_enqueue_script` statement. Are you using `wp_enqueue_script` inside some action hook? Because you have to. I use it like this:
add_action( 'admin_enqueue_scripts-options_page-{page}', 'myplugin_admin_scripts' );
function myplugin_admin_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
} | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 3,
"tags": "jquery ui"
} |
Allow users to enter and edit data in one-to-many configuration
We would want a user to login and be presented with a form that they would potentially have to submit multiple times (disclosures of any industry relationships, one form per disclosure).
The challenge is how do we capture and display what has been previously entered by a user when they log back in and give them a chance to delete or edit previous entries without investing in a ton of custom coding because we have a very tight deadline on this project.
Has anyone seen WordPress do data collection and management in this manner on a per-user basis and if so, which plugins or other add ins were used? | The Formidable Pro plugin (paid) does what I was describing. It allows a logged-in user to submit a form multiple times and also will display a list of entries and a link to edit each one. Gravity and Wufoo don't match up. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, plugin recommendation, database, forms"
} |
Can I run multiple blogs from my local machine
OK I head that WP can now host more sites using one installation. I host my blog on my own computer using MAMP and latest WP.
But I can't find option to create another blog? | To achieve this simply, make sure your WordPress version is 3.0+. It is always recommended that you have the latest.
First you need to activate the network: <
Note that, as you are using a local installation, you won't have the choice to create your network in sub-directories as subdomains won't work. By reading and following the information in the link above, you'll get what I mean. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "multisite, local installation"
} |
Creating the modern 'single page' html5 css3 layout in wordpress
I am considering to develop a new portfolio website in the form of a single page website. I do not know if this is a new concept, but I see it becoming popular for portfolio websites, it is also quite a handy form.
Now I want to create the about, portfolio, contact on one page, and have a normal blog on another page. So actually there is one single page, and one blog page.
To give you an example of the single page, here is a link to a tutorial that creates such a single page. But this is just a normal static page.
<
Now is the best way to go about this to just create a single page, and have all my content displayed there just formatted in one big pile of html.
Or is there a more elegant solution to do this. Maybe with several custom post types on a single page, or is this not possible or not efficient.
_I am pretty new to wordpress, sorry for if this is a stupid Q_ | here's how I would set things up, not necessarily the correct / best / only way.
* create a home page, blog page, about page, contact page, etc.. as individual pages.
* create a custom post type for my portfolio items.
* use posts as the blog posts.
* set static front page to my home page, blog page as the posts page.
* create a front-page.php template, this will load whatever content I have in home by default.
* use get_page and wp_query to load all of my pages and portfolio items into the template.
* use a caching plugin to make it all nice and speedy | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "theme development"
} |
How to change wordpress news root url
I have a site and my customer has decided the url for what used to be news should now be renamed to tips-and-tricks, but we want to keep the old urls too because we don't want to lose old links. I've tried several .htaccess settings but that's really not my field of expertise, and I'm not even sure if this is the right way to achieve this with WordPress.
So, for example:
site.com/news
should become
site/tips-and-tricks
but /news should point to /tips-and-tricks as well. Can I do this and what is the best way to do it with WordPress? | In admin create a page with slug tips-and-tricks. Than go to Settings->Reading than in first section set up your new page to be your posts page. WP will handle proper redirection of old permalinks to new. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "htaccess"
} |
Strange Search Query Appearing on Google Index - "/?q=Save+Us+From+Berlusconi"
Strange.
Stripping my site URL, and searching for the term "/?q=Save+Us+From+Berlusconi" on Google shows up this blog post written way back in 2009: <
My site is facing something similar.
What should I do? Is this really a bug from Google? It looks like Berlusconi is the prime minister of Italy; however my site has nothing to do with political stuffs. I see there are a couple of threads in Google forum -- older ones -- that talk about this strange query indexed on Google.
Example query:
Check the second URL. | This is not a WordPress question … yet.
There are two ways to handle this.
1. **Don’t do anything.** One more indexed page will not harm your site’s karma. This is not spam. Someone has has probably created a link to your site with this query string to trick the auto-complete tool on Google. The link may be gone now, but Google doesn’t forget. So what?
2. **Fix your search.** I tested the search string on the website from your profile and I got many “results”. That’s a problem. You serve exactly the same set of articles for every search. This is not useful for your visitors. Plus, if some bad guy creates a file with 10.000 links to different searches you get a serious duplicate content problem. Install a good search plugin – I suggest Relevanssi – and make sure to show only real results. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, search, seo, google search"
} |
Weird undefined index: id,std notices. How to fix it?
Ok I'm running my wordpress in debug mode. I'm getting lot of notices.
This is my code.
<?php
//allows the theme to get info from the theme options page
global $options;
foreach ($options as $value) {
if (get_option( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; }
else { $$value['id'] = get_option( $value['id'] ); }
}
?>
This is what i'm seeing.
Notice: Undefined index: id in functions\get-options.php on line 5
Notice: Undefined index: std in functions\get-options.php on line 5
These notices repeated around 20 times. Whats wrong in my code?. Can anyone help me to fix those errors. Thanks. | First: Write `false === get_option( 'whatever' );` \- see Coding Standards.
Second: Why do you have a variable-variable in there? `$$value['id'] = $value['std'];`. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme options, debug"
} |
Is there a way to rename "themes" directory name?
By defining TEMPLATEPATH, STYLESHEETPATH, WP_CONTENT_DIR and WP_CONTENT_URL merely affect the naming changes to wp-content.
Is there any way to redefine the theme path and plugin path, so the new path can propagate through function calls such as get_options or bloginfo? | For themes you can use `register_theme_directory()` function to add additional directories for WP to be aware of. I don't think I ever seen this used in practice, so not sure if there are any complications possible.
For plugins you can define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` constants in `wp-config.php`. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 1,
"tags": "customization"
} |
All my files are on my blog! I need sync solution
I uploaded all my files on my blog (self hosted). Now all my files (documents, photos, etc...) are somewhere in wp-content/upoads folder...
Is there a way of having all my files in their folders (documents in docs folder, photos in photos, etc) but still have them available trough wordpress...
Thanks | Check `Settings -> Media -> Uploading Files` | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "uploads"
} |
Application / Admission Form plugin
I'm looking for a plugin that would allow tracking of an application similar to the admission forms used for colleges. Ideally, a student would be able to fill out the application and submit it (and pay, if there's a application fee) and the student could check back periodically on the status of application, i.e. Received, Under Review, Accepted / Rejected, etc.
On the Admin side of things, the applications would show up and would allow the admin to review, make notes, etc and mark the application with a new status.
Has any one seen or heard of a plugin to do something like this? | I'm currently using Gravity Forms, which is doing something close to what I want for this. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugin recommendation"
} |
long blog post on self hosted wordpress blog not displayed
I have my self hosted wordpress blog here I recently created a blog post which is very long with so many pictures and text, but i suddenly found that my blog post was not displayed but if i cut short the length by deleting some content then the blog gets displayed can anyone help ? Thanks in advance here is the link to my blog post which is not getting displayed | Really long posts need to be paginated in order to be dispalyed. So using `<!--nextpage-->` tag I paginated the post and it finally works. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, blog"
} |
Add Piwik Tracking code to page
I use piwik analytics to track the visitors to my website. I recently created a blog on WordPress and wanted to added the same tracking code that I use on the plain HTML webpage. How can I added the tracking script in the php in order to track my blog visitors?
thanks! | Add the tracking code to one of your theme files, most likely `footer.php`.
The easiest way to do this is to go to your admin panel and go to Appearance > Editor, and on the right side, find the entry for Footer (footer.php), and then insert the code right before the closing `</body>` tag. Update the file by clicking the button below the text box, and you should be good! | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "html"
} |
Can I have the same wordpress site under different url?
Can I run the save a wordpress site under different domain names? Like mydomain.com and mydomain.net ? Where the domain name will NOT change in the address bar of web browser. | Typically this is a really bad idea ( Google hates duplicate content).
If you need to do this you can edit your servers host file, but in reality unless you have a specific reason you should be using a 301 re-direct. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "domain, domain mapping"
} |
Add custom post type to query
$saved = $wp_query; query_posts(array('tag__in' => $tag_array, 'showposts' => $args['posts_per_page']));
I need this to query standard posts and a custom post type called "property"
I can't seem to get it to show anything from the custom post type when I tried to include another array.
Thoughts? | You need to include `post_type=`.
Your query would be an array of post types since you want 2 `'post_type' => array( 'post', 'property')`
< | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom post types, loop, query"
} |
make a dropdown custom field with 'cities' list in it
I am developing a website for real estates. I was wondering that how can I add a dropdown to my custom forms (theme my login plugin) for cities states etc. The basic point is that I dont want to add new tables in the database. I want to achieve this without that.
Thanks | You can register custom taxonomy like so:
<?php
// Register custom taxonomy for locations
function mamaduka_register_taxonomy_location() {
register_taxonomy( 'location', array( 'post' ), array(
'hierarchical' => true,
'label' => 'Locations',
'public' => true,
));
}
add_action( 'init', 'mamaduka_register_taxonomy_location' );
?>
for more information about custom taxonomy see Codex: < | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "custom field, dropdown"
} |
If post custom meta data is not set, show normal state
I'm much of a php-noob but have this idea of a loop for my site. I have the idea behind it but maybe you have an idea how to put this into code:
$customfield = get_specific_customfield
if $custom-field is = not empty
echo 'custom-field-input" class="'
else
echo '`<?php echo $thumbnail_src[0]; ?>" class="fancybox`'
(I have to integrate the fancy-box stuff to control how the input will be displayed) | To get a value of a single custom field use
<?php
$post_id = $post->ID;
$key = 'value'; // change value to what custom field you are looking for
// To retrieve only the first value of given key
$customfield = get_post_meta($post_id, $key, 'true');
// To use as default
$customfield = get_post_meta($post_id, $key);
// Then check what you got
if($customfield)
?>
<img class="thumb" src="<?php echo get_post_meta($post_id, $key, true) ?>" alt="<?php the_title(); ?>" />
<?php
else
echo 'whatever you want to show by default';
?>
For further reading goto codex
Hope it helps you | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom field, post meta"
} |
Allow customers to download updated versions of software
I will shortly be creating my WordPress website in which I will be selling a software product. Ideally, I would want two things to happen :
1) When a customer makes a payment(through PayPal account or PayPal credit card processing I suppose), they should be redirected to the download page to immediately download the software.
2) Since software tends to be updated into new versions quite a lot, I would really like to have a flexible way to allow customers to re-download the software using a well secure, secret uri, probably created with a token and based on some passwords.
Hence, I would like to ask you how you would suggest I should handle that. I know that there are some WordPress plugins that would allow me to do (1), but i would really like to know your experience and if you use one, which plugin do you suggest?
For (2), I don't really have any ideas yet? Is there a plugin or other solution ? Has anyone has done it? | I think you need the Wordpress Eommerce plugin. It's free if you use the standard gateways, and then $40 for the additional payment gateways ("gold cart").
<
Customers will be able to purchase your item, and then download it immediately. They can have an e-mail with the link to the download as well, and there is an option to allow downloads for digital content after the customer pays, and you can specify options such as how many times they are allowed to download the content (it tracks this to help prevent link sharing).
If you set a reasonable number of times they can download the software, or just make the link good for unlimited downloads and keep an eye on the download counts, you could updated the linked digital content and thus allow customers to pay for your digital content, and then download updated versions. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, plugin recommendation"
} |
Can I allow certain people to add/edit pages within a parent?
I'm planning on building a site with different sections, for example:
* Training
* Conferences
* Ideas
A different person will be in charge of editing and managing each section. They will be able to edit the parent page and add, edit and delete sub-pages within each section. I don't want each person to be able to add/edit/delete pages from a section that they don't manage.
As far as I can tell if I give each person an "editor" role then they will be able to add/edit/delete pages from each section. If I give them an author role, then they won't be able to add pages at all.
Is there a way to achieve my goal from within Wordpress? If not, will I need to use a plugin, and if so, can you recommend one that will help? | Try Role Scoper: < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "plugins, pages, user roles"
} |
how do I group content in magazine-style 'issues'?
I am building a website for a magazine. It won't carry the whole content of the mag, just a teaser article or two from each issue.
I need to have a page for each issue that features these articles, something like:
I'd make a template for 'issue' pages that spits out all the associated articles. But wouldn't this mean the client would have to create a blank page for each new issue, and assign the template? That seems eminently breakable. If it could be done dynamically that would be preferable.
An alternative would be putting each page in a numbered category and using the standard archive output for that category, but I'd rather use categories for their intended purpose.
Is there a standard way of doing it? | This scenario seems like an ideal opportunity to create a _custom taxonomy_ for the magazine's Issues: e.g. Taxonomy = _issue_ , and Terms = _August 2011_ , _September 2011_ , etc.
You could even create a hierarchical taxonomy of _Volume_ and _Issue_ , with terms e.g. _2011_ and _August_ , respectively.
Then, you have archive pages for each issue, and you can create custom Loops based on the taxonomy. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "custom post types, categories, loop, cms"
} |
wpdb->insert: do I need to prepare against SQL injection?
Do I need to use wpdb prepare before wpdb->insert?
If I am inserting values into a wordpress table using wpdb->insert, do I need to "clean" my data before inserting it or does this method (wpdb->insert) do that for me? | No, you shouldn't prepare or escape the data, this is done for you by the `wpdb` class.
From the wpdb class reference:
> **data** :
>
> (array) Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
If, however, you were writing your own SQL rather than using the `insert` method, then yes, you should escape using `prepare`. | stackexchange-wordpress | {
"answer_score": 24,
"question_score": 21,
"tags": "wpdb"
} |
get_shortcode_regex() only matches first shortcode
The Codex has an example of using get_shortcode_regex() to check if a shortcode is being called on a given page:
$pattern = get_shortcode_regex();
preg_match('/'.$pattern.'/s', $posts[0]->post_content, $matches);
if (is_array($matches) && $matches[2] == 'YOURSHORTCODE') {
//shortcode is being used
}
This only detects the first shortcode in the post content, though. Is that a bug with get_shortcode_regex(), or can the preg_match() parameters be tweaks to make it return all shortcodes present on the page? | From PHP docs (emphasis mine):
> preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because **preg_match() will stop searching after the first match**. preg_match_all() on the contrary will continue until it reaches the end of subject. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "shortcode, regex, bug"
} |
if there is only one post in the category, directly open
I have a few categories.
in each of them, I have only one post.
by clicking on a category, I have to click on that single post to enter.
I wish, by clicking on the category, enter directly in that one post.
This method avoids having to click two times in the post.
Any suggestions for what I have to use code in archive.php? | this function will check if you're on a category page and 302 redirect to the latest post in that category. put it in your theme's functions.php file.
function my_check_if_cat(){
if ( is_category() ) :
$category = get_the_category();
$latest = query_posts('showposts=1&cat='.$category[0]->cat_ID);
if(have_posts()) :
wp_redirect(get_permalink($post->ID), 302);
endif;
endif;
}
add_action('template_redirect','my_check_if_cat'); | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "archives"
} |
Windows Live Writer inconsistent with Media Library
I'm considering moving my existing blog from DasBlog to WordPress. While doing some tests to see if I did like the platform I ran into following problem:
I'm using Windows Live Writer to write my blog posts. I'm used to add the pictures on the original size and remove the default link (to the full size picture). When I publish this post to WordPress, some pictures end up in the picture library and others don't, even in the same post.
It would be nice to have a consistent way of storing my pictures. Preferably without the use of the media library, as I don't see the use of it (yet?) and it gives unwanted links and records in the posts table. | You can make WLW upload images directly via FTP, you can set this up in settings of connection to your blog.
However as long time WLW user myself I would strongly suggest you to try and make sense of media management in WP, even if it seems excessive at moment (it did to me for a long time). Down the road you will very likely come to some things that are much easier done with media library, rather than organized bunch of directly uploaded files.
I know this very well myself, because I am facing need to re-organize and import three years worth of media at my blog. :)
PS WLW is fine, but do try writing posts in WP itself. A lot of work went into that part of experience and it is very impressive by now. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "media library, windows live writer"
} |
WordpressMu network with private sites
Anyone know a way to have WordpressMU to work like this:
New user registers an account and thus is registered for the whole network (default functionality in WP Multisite), but then he/she would be required to "ask" for an access for the sites within the network one by one. The network home page would be accessible for everyone, but the subsites should be private.
So in essence, the user has one username and password for the whole network, but in order to view the site, the user has to be given rights to do so site by site basis by the admin of the site.
Any ideas? Plugins? Anything? | By deafault, any sub-site is open to public. You would need to add code to check if a user is logged in. And if user is logged in, does he have the right priviliges?
What I would do, is to create one new `role` for each sub-site. Then when a new user registers, I would manually add the right sub-site role to the user, thus giving him access to the site.
You can use the members plugin for managing roles: < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "multisite, private"
} |
How to handle sql with Custom List Table Example
I am using the Custom List Table Example plugin as a base to display entries from a table I created in the wordpress database...
However I am having issues with this function
function column_default($item, $column_name){
}
I get the error message:
Fatal error: Cannot use object of type stdClass as array in
In the example in the plugin, it uses a simple array. But the $data returned from the query returns several rows of data (i.e. an array with object, object, object).
Inside of my prepare_items() function:
global $wpdb;
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to title
$sql = "SELECT * FROM wp_nc_location ORDER BY " . $orderby;
$data = $wpdb->get_results($sql); | Got it working by passing $item as an array
function column_default($item, $column_name){
$item = (array)($item)
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 3,
"tags": "wp list table"
} |
Widget options - where to put them?
I have a widget which I want to add a couple of options. The options are effectively 'global' for the widget - username and password details to a secured web service.
So in effect, wherever the widget is used the same parameters will be used.
I presume I should use an add_options_page? Or ...
Add options on the widget itself? Or ...
can you do both? | I have answered this myself by adding an options page and adding options to the database. The functions are
add_option('yourpluginoption1','value');
add_option('yourpluginoption2','value');
add_action('admin_menu', 'yourplugin_menu_');
function yourplugin_menu_() {
add_options_page('etc etc... | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "widgets, options"
} |
Tags as a dropdown with set tags
Sorry if this is a silly question but is it possible to have a taglist as a dropdown?
I have a page where users can post theyre own content, and I would like them to be able to choose certain tags as a dropdown, is this possible?
Heres the page so you can see <
I appreciate any help what so ever, anything is a huge help!
Thanks | You can use `wp_dropdown_categories()` to create your dropdown:
wp_dropdown_categories(array('taxonomy'=> 'post_tag','hide_empty' => 0, 'name' => 'my_tags'));
## Update
the reason you are getting the term ID is because `wp_dropdown_categories` sets the ID's as values so instead of just echo'ing it out you need to get the term, something like:
$term = get_term_by('id',$your_id,'post_tag');
echo $term->name; | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 2,
"tags": "tags, dropdown"
} |
Does WordPress MultiSite use separate MySql databases?
I ask because I cannot find the options from a plug-in I created on my second blog.
Adding this plug-in to the main site and the options show up.
I am confused because there is a column in **wp_options** table **blog_id** and I was expecting there to be more than one value there. | WordPress MU uses one database and each blog gets his own tables with the blog id in the prefix, so once you install a network installation your database should have these tables:
* wp_1_categories
* wp_1_comments
* wp_1_link2cat
* wp_1_links
* wp_1_options
* wp_1_post2cat
* wp_1_postmeta
* wp_1_posts
* wp_blogs
* wp_blog_versions
* wp_registration_log
* wp_signups
* wp_site
* wp_sitecategories
* wp_sitemeta
* wp_usermeta
* wp_users
And every new site you set up will create separate tables for example:
* wp_2_categories
* wp_2_comments
* wp_2_link2cat
* wp_2_links
* wp_2_options
* wp_2_post2cat
* wp_2_postmeta
* wp_2_posts | stackexchange-wordpress | {
"answer_score": 10,
"question_score": 1,
"tags": "multisite, database, options, configuration"
} |
Is using %postname% for permalinks really that bad for performance?
I've seen in various places, including the Wordpress admin and on this page, that using string based identifiers is "strongly not recommended for performance reasons".
I understand that looking up a string in the database is slower than looking up an integer, but in my experience it's never a huge difference, assuming the slug field has a fulltext index.
Why is there such a strong discouragement of using this method? | This is much more complex than looking up string versus integer. WordPress sifts permalink through a set of persistent regexp-based rules. And it affects logic a lot that string might be many more things than number. See one of better writeups on topic for details.
Practical point to know - this doesn't concern most sites, except those that have many pages (like PAGE pages, not posts).
Even better point to know - this is all getting fixed in WP 3.3 and will be thing of the past. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "permalinks, slug, performance"
} |
WordPress uploads directory. Featured Images storage
WordPress stores all uploads in:
_**/uploads/year/month/_**
I want to store featured images of my custom post type like:
_**/uploads/myCustomPostType/_**
No date subdirectories etc. I want all the files to be EXACTLY in the same directory.
Also I'd like to have these files resized before placed in the folder(I guess `set_post_thumbnail_size()` will be good enough).
Is it possible?
**[edit]**
If you wonder why I'm asking for that - the answer is Piecemaker I (I don't like the latest version). I want it to display images from **Slider** custom post type automatically and unluckily Piecemaker takes two arguments - filename (different for every file) and file directory (the same in all cases, so images added in different months won't be displayed together). | After all I figured out I'm able to get exact address of these files using to use get_post_thumbnail_id(), wp_get_attachment_url(), wp_get_attachment_thumb_file(), wp_get_attachment_image_src() within piecemakersXML file. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "customization, post thumbnails, uploads"
} |
Building a plugin that doesn't break when deactivated
I wrote a WordPress plugin that creates an admin page for deciding what posts go in a feature slider on the front page. Everything works fine and I'm simply calling to the function inside the plugin with
<?php uwffs_display(); ?>
in the home.php file.
The issue is that if I were to deactivate the plugin, the home page breaks at the point the
<?php uwffs_display(); ?>
function call occurs and stops rendering the rest of the page.
What is a more graceful way I can call this plugin's function so that, if deactivated, it will load the rest of the page?
One thought is I could write it as:
<?php if(function_exists('uwffs_display'))
{
uwffs_display();
}
?>
Is that the best way? | The other option would be to use any hooks available in the Theme, which would allow your Plugin to inject the slider at a filter or action hook. If the Plugin is deactivated, its `add_action()` or `add_filter()` call is never run, nothing attempts to be added to the template, and, voila: no breakage.
But, barring that (and since Themes that offer such custom hooks are still in the minority), `function_exists()` wrapper is the way to go. So +1 to @rmlumley. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 3,
"tags": "plugins"
} |
Categories lose hierarchy order once assigned to post
I setup some hierarchical categories and when I assign them to a post the widget reflows and loses the hierarchy display. Example:
- Education Services
-- Arts & Archives
--- Fine Arts
-- Reference
-- Health Sciences
When selecting "Education Services" & "Reference" (marked with 'x') the widget appears like this:
x Education Services
-x Reference
- Arts & Archives
-- Fine Arts
- Health Sciences
So since the selected (top-level) parent goes to the top, all children besides the selected one look they have lost their parent (even though they actually have not).
I have read some other forums post/support tickets but not much about this issue. Any suggestions? | You could try out Scribu's plugin, i believe this addresses the very problem you're describing which has been reported on Trac a handful of times(but closed/deleted).
**Category Checklist Tree** by scribu
<
**Related tickets:**
* <
* <
Hope that helps.. :) | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "categories, widgets, hierarchical"
} |
Specific Thumbnail Size for Custom Content Type
Is there any solution for setting specific thumbnail size for any custom content type?
Thanks. | It seems to me the quickest way to do that is:
1. Add your specific thumbnail size to functions.php. Here's the code to do it.
2. Find the specific template file in your theme that displays your custom content type, then modify it to display your recently added thumbnail size. Use the following code, enter the specific thumbnail id you added in point 1 as the parameter.
3. Additionally, you can use the **AJAX Thumbnail Rebuild** plugin so WordPress create thumbnails in your specific size. This is especially useful if you already have a running site with plenty of thumbnails in place. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom post types, post thumbnails"
} |
How do I get my child-theme to work with my theme's includes folder?
I am using the Canvas WordPress theme (by WooThemes.com) and successfully made a child-theme to override my CSS. However, I would also like to apply the same child-theme principles to my theme's "includes" folder which contains a variety of .php files. Any idea how I can go about doing this? | Depending on how Canvas calls in those files, you might not be able to do this.
If they're using locate template or something similar (get_template_part, for instance), you'll just need to create your own includes folder in the child theme and name the files the same as their couterparts in the parent theme.
If the parent theme uses require or require_once (or include/include_once), there's not going to be an easy way to override those parent theme files.
What are you trying to replace? | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "theme development, child theme"
} |
Get paged category link programmatically
I want to get the link to a category (specified by id) but with a paged value (e.g. page 3 of category id 4).
I was looking into `get_category_link()` _Codex_, but it only returns the link to the first page of the category.
Is there a build-in function that I can make use of to get the link to a category page that reflects the blogs URL-layout settings (`?paged=3`/ `/page/3`)?
**Edit:** I added my solution as an answer. | This the code I have so far which looks like it does the job, I still wonder if there is a API function for the job:
/**
* @param (int) $category_id
* @param (int) $pagenum
* @return string
*/
function get_category_paged_link($category_id, $pagenum)
{
global $wp_rewrite;
$link = get_category_link($category_id);
if ($wp_rewrite->using_permalinks() || $wp_rewrite->using_index_permalinks())
{
$link = sprintf
(
'%s/%s/%d/',
rtrim($link, '/'),
$wp_rewrite->pagination_base,
$pagenum
);
}
else
{
if (false === strpos($link, '?'))
$link .= '?';
else
$link .= '&';
$link .= sprintf('paged=%d', $pagenum);
}
return $link;
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, links, api"
} |
How to set up default values for a plugin?
What is the best way to go about setting up default values for a plugin? Should I just insert those values into the wp_options table?
AND...if that's the best way to go about it, I have another question. My options are listed as a group which currently looks like:
a:4:{s:26:"nc_location_drop_down_zoom";s:2:"14";s:17:"nc_location_width";s:3:"200";s:29:"nc_location_drop_down_maptype";s:7:"roadmap";s:11:"text_string";s:0:"";}
Is this a serialized array? How do I do an insert like this into the table? (I realized this is more of an sql question...) | Use the Settings API and save your data in a single option as an array, WordPress will serialize the data for you. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 7,
"tags": "options, sql"
} |
Is there an A/B testing plugin that lets you vary the heading, featured image, and content in a Wordpress post?
If not, are there alternate solutions that can let me accomplish this? Do I need to develop my own plugin? | ShrimpTest is a simple and easy way to add AB testing all over a site:
< | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 4,
"tags": "plugins, testing, posting"
} |
redirect out of wp-admin, without losing admin-ajax.php
I'm trying to keep all non-administrators out of the Wordpress admin panel by using a wp_redirect inside of an is_admin conditional. The problem is that a side effect of this if that non-admins can no longer use the file "admin-ajax.php" for ajax calls in Wordpress. It appears that a few people on the Wordpress forums are having the exact same problem lately.
Would anyone have a solution for this? | Check the `DOING_AJAX` constant:
function my_admin_init(){
if( !defined('DOING_AJAX') && !current_user_can('administrator') ){
wp_redirect( home_url() );
exit();
}
}
add_action('admin_init','my_admin_init'); | stackexchange-wordpress | {
"answer_score": 8,
"question_score": 5,
"tags": "ajax, wp redirect"
} |
Wordpress themes that are browser tested and maintained?
Are there any developers that offer themes that have a defined list of browsers tested, on desktop and mobile devices, that are also periodically updated to account for new browser versions? | Okay, well, I've found <
Details on each theme include: Compatible browsers WordPress version Documentation detail Layout type Types of source files included Widget ready
Looks pretty good to me. Will give it a try. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "themes, testing, browser compatibility"
} |
What methods to use to create small, editable pieces of text for static pages?
For many of the sites I do for clients, the designers will make pages with small pieces of text in various places. For example, the home page will have a headline, a tagline, and a small box with contact information. The about us page will have a main body of text, but then also a side box with a past client quote in it. The contact us page will have a short blurb before the form.
The client wants the ability to edit all of these pieces of text later on. Are pieces such as these what widgets are supposed to be used for? If so, how would I allow the client to update the text later on? It seems messy to make a separate widget area for every static page, and it doesn't seem like this would allow the client to later edit the text very easily. Would concepts like custom post types, metaboxes, or shortcodes be useful here? I've tried many different methods but I'm not satisfied with any of them so far. | Typically you use widgets or custom post types but in reality these solutions can be unfriendly to clients. WordPress still revolves around the idea of a post based loop so doing traditional "content blocks" that you might find in other frameworks can be difficult. Fortunately there are plugins that are pretty good in this area.
I recommend checking out the following two:
<
< | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 8,
"tags": "pages, content"
} |
how to limit and display tag?
Hi i need to show random 3 tags for a post. all my posts have been tagged with more than 10 tags, i need to display any 3 tags randomly.
for eg:
A sample post
<a href="/tag1">Tag1</a>
<a href="/tag2">Tag2</a>
<a href="/tag3">Tag3</a>
I am currently using `<?PHP the_tags()?>` to generate all tags how to restrict it to 3 randomly generated tags. | Try this:
$posttags = get_the_tags();
$count=0;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
echo '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a> ';
if( $count >4 ) break;
}
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, tags, array, template tags"
} |
How to correctly get post type in a the_title filter
I want to prepend text to the post titles of a specific custom post type, but the filter below didn't work. Instead of changing only that CPT's post titles, it changed _all_ titles on the given CPT's pages—menus items, posts in secondary loops, etc.
What am I doing wrong? I'm guessing it's something to do with the scope of get_post_type().
add_filter( 'the_title', 'add_cpt_prefix' );
function add_cpt_prefix( $title ) {
if ( get_post_type() == 'press' ) {
$title = '<span>Press:</span> ' . $title;
}
return $title;
} | You can exclude menus by testing the post id :
add_filter( 'the_title', 'add_cpt_prefix' );
function add_cpt_prefix( $title ) {
global $id, $post;
if ( $id && $post && $post->post_type == 'press' ) {
$title = '<span>Press:</span> ' . $title;
}
return $title;
} | stackexchange-wordpress | {
"answer_score": 7,
"question_score": 4,
"tags": "custom post types, filters, title, actions"
} |
Is it possible to store arrays in a custom field?
If I understand correctly, custom fields work like this:
key(string/int) => value(string/int)
Is it possible to define a custom field like this?
key(string/int) => value(array (string/int, string/int))
I want to use such a structure for storing a series of quotations in [quote, source] format, thinking that it would minimize potential input error compared with, say, str_splitting a single value. | Yes you can, either by code:
$demo = array('value1','value2','value3');
update_post_meta($post_id,'meta_key',$demo);
Or simply using the custom fields UI, add ass many values as you want one at a time and make sure they all have the same meta_key. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "custom field, post meta, array"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.