INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
How to create custom URLs for Custom Post Type sub sections? Not sure how to ask this, because I'm not exactly sure what I'm asking. I'm looking to use custom URLs (using rewrite rules maybe?) to create 'tabs' for a Custom Post Type. In the past I've used things like a GET session variable to determine what tab the user is on, or JavaScript. I would really prefer to keep it on it's own logical page with a URL to reflect that. A very basic look of the tabs would be: `HOME | UPDATES | CONTRIBUTORS | WALL` For example if we're on the CPT of Charity's sub page of Updates: `
Create an end point for the permalinks. See example. Then you can even be more granular and use `updates/2012`, `updates/2013` and so on. Recommended reading: * Codex: `add_rewrite_endpoint()` * A (Mostly) Complete Guide to the WordPress Rewrite API
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "custom post types, url rewriting" }
Retrieve featured image We are building an Android app based on a Wordpress mysql database. We were able to get most of the information from the datase to display on to the app. Now all we have left is to retrieve the posts featured image. Is there a way to have the featured image output a URL? Thanks!
The featured image attachment id is stored in the post_meta table, with the meta_key `_thumbnail_id`. Use that post id to find the post meta with meta_key `_wp_attachment_metadata`. The value of that is a serialized array with keys `thumb`, `file`, `width`, `height`, `sizes` (an array), and `image_meta` (an array). The `file` value is relative to the uploads directory for the WP install, and points to the original full-sized image. You should be able to calculate the URL from that. `sizes` has an image size as its key (e.g., 'small', 'medium', 'large', 'thumbnail'), and the value is an array with keys `file`, `height`, and `width`. `image_meta` will contain things like exif/iptc image metadata from the image itself.
stackexchange-wordpress
{ "answer_score": 15, "question_score": 8, "tags": "images, mysql, android" }
displaying posts from a custom post type tags I created a custom post called projects and a taxonomy called tagportfolio , in the admin panel i created 3 tags under this taxonomy to filter my projects portfolio page the three tags is 1. Urban planning and upgrading 2. Urban Design and Landscape 3. Architecture and Interior Design under each tag there is a posts , now i need to know how i can display the posts that under each tag for example: posts under tag Architecture and Interior Design in a page template Thanks N.B this is the custom post and taxonomy functions git://gist.github.com/3066834.git gist-3066834 this is how the child tax should be displayed {like the main tax} git://gist.github.com/3061479.git gist-3061479
You're looking for WP_Query echo '<ul>'; //The Arguments $args = array( 'post_type' => 'project', 'tagportfolio' => 'urban-design-and-landscape' //should use the slug name not the full name ); // The Query $the_query = new WP_Query( $args ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); echo '<li>'; the_title(); echo '</li>'; endwhile; echo '</ul>';
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy" }
get_posts with meta_compare='LIKE' not working I am using the following code: $tolettpe = "Sale";//default if($_REQUEST['tolettype']) $tolettpe = $_REQUEST['tolettype']; else if($_REQUEST['srch_type']) $tolettpe = $_REQUEST['srch_type']; $args = array( 'numberposts' => $latestcount, 'category' => $catidstr, 'meta_key' => 'property_type', 'meta_compare' => 'LIKE', 'meta_value' => $tolettpe.'%' ); $post_content = get_posts($args); The value in the database is 'Sale||' and there are no query string variables in the request. But the query returns no results. If I use the exact value and no meta_compare, it works. Any ideas how to make this work?
`meta_compare` Possible values are `'!=', '>', '>=', '<', or '<='`. Default value is `'='` if you want to use `LIKE` you need to create a meta_query eg: $tolettpe = "Sale";//default if($_REQUEST['tolettype']) $tolettpe = $_REQUEST['tolettype']; else if($_REQUEST['srch_type']) $tolettpe = $_REQUEST['srch_type']; $args = array( 'numberposts' => $latestcount, 'category' => $catidstr, 'meta_query' => array( array( 'key' => 'property_type', 'value' => $tolettpe, 'compare' => 'LIKE' ) ) ); $posts = get_posts($args); The generated query puts the search term between two % signs, so there is no need to add any in the code.
stackexchange-wordpress
{ "answer_score": 12, "question_score": 6, "tags": "get posts" }
Plugin that integrates Google Storage with WordPress? W3 Total Cache and CDN Sync Tool (w/ WP Super Cache) are two plugins that do a pretty good job of integrating various Content Delivery Networks (CDN's) — including Amazon S3 / CloudFront, CloudFiles, and MaxCDN (among others) — with WordPress. But I am looking for a plugin (free or paid) that integrates Google Storage (not to be confused with Google Drive or others — see pricing) with WordPress, and so far, could find none. Has any come across a plugin that does this, by chance?
The WP2Cloud plugin now supports Google Cloud Storage (in addition to Amazon S3).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 4, "tags": "plugin recommendation, cdn" }
Hide a subdirectory on my website hosting I have a website www.mcruiseon.com. I have added .htaccess to get all www.mcruiseon.com to redirect to www.mcruiseon.com/wordpress. But the 'wordpress' still shows up on my html link on browser. Can I hide the fact that the website is hosted under a folder wordpress ?
If understood correctly, you'll have to follow this Codex instructions: Using a pre-existing subdirectory install. > If you already have WordPress installed in its own folder (i.e. < then the steps are as follows: If that's your case, you'll learn how to make WP work as if it were on the root, even being installed on a folder. If your actual `.htaccess` only have the redirection you mention, you can delete it, otherwise make a backup so you can merge it with the new one (from WordPress).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "htaccess" }
How do I get the next page of posts link? Functions such as get_next_posts_link allow you to get the HTML link to the next page, with few parameters for change (label and max pages). I want to get the URL to the next page so I can add custom classes to the link.
Why build the link yourself, when you can just add the class to the result of `get_next_posts_link()`? add_filter('next_posts_link_attributes','example_add_next_link_class'); function example_add_next_link_class($attr) { return $attr . ' class="example-class"'; } Now the link sent back by `get_next_posts_link()` will have your class in it.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, pages" }
Do I have to set parent when set post term? When save a term which is a child term, if I don't provide specific parent id, will WP make this term's parent 0 ?
When you create a term for a hierarchical taxonomy, if you don't specify a parent, its parent ID is set to 0. In other words, it becomes a parent term. * * * Edited with regards to comments: * Add specifically each term you wish to add to the post (parent terms aren't automatically added if their children are). * Adding terms to posts does not effect the terms relationship with each other (i.e.. child-parent relationship remains in tact).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "terms" }
plugin shortcodes not working on custom theme- unsure how to fix Live site. I've got a custom theme that is giving me slight issues with shortcodes- they don't work. When I switched back to the default theme, the shortcodes worked fine. What do I need to look for in my custom theme to be the culprit? If it matters, the shortcodes are for Contact Form 7 and Bookings plugins. contact.php <?php /* Template Name: Contact */ ?> <?php get_header(); ?> <h2>Tell us, what's on your mind? Questions, comments, hellos- share them below.</h2> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php get_footer(); ?> Any and all help is greatly appreciated.
Your problem is the loop itself. As others suspected, you don't have `the_content()` to display the page content. Change your loop to this and that should fix your problem: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "plugins, shortcode" }
Custom Post-to-Post with multiple parents? I currently have a custom post type of "Faculty" - each faculty can have zero or many custom post type "Bibliographies," and a bibliography can belong to one or more faculty. What is the best practice for setting up this association, and more importantly, is this possible still using the API? I'm testing this with 3.4.1.
When its about setting up Post to Post relations, I find the scribu's Posts 2 Posts plugin the best out there. the plugin not only does provide the interface but also provides the API to handle the relations.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom post types, api" }
Best architecture for multiple websites Im currently administering close to 20 separate wordpress installs and now Im at the point where I need to work out a plan going forward. As a sole operator, I just haven't had the chance to invest in this prior to now. What Im considering is two approaches. 1) Run Wordpress in a Multi-site configuration. In this setup, Im assuming and from what I have read I will have one install on WP, plugins themes and each site that comes in uses the same database. That way I can simply update the one version of core and go from there. 2) Keep everything separate and get up to speed with WPRemote or ManageWP and manage the sites that way. This to me would fit best into my current situation and I would be able to slot it straight in. I was hoping to get some advice form others that have gone down either route and how they found the practicality of each. Thanks in advance.
As awesome as MultiSite can be, it's certainly not _always_ the answer to this situation. A first glance, you have the advantages of: 1. One install (easy to upgrade) 2. Easy to manage (with the help of the single sign-on plugin) 3. Plugins & themes are shared - again, easy to maintain & upgrade But in retrospect, these can equally work against you - since everything's "in it together", upgrading the core/plugins/themes might break individual sites (depending on their setup). There's no isolation like you would have with individual installs. If you opted for a manager like WPRemote, you get the advantages of MultiSite's "central hub", but with the benefit of granular control. Also weigh up the fact you'll need to migrate all your existing sites initially, which I'd argue would require some time to set up & ensure everything is working smoothly. **TL;DR:** Go for WPRemote (or similar).
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "multisite, plugin recommendation" }
Loop that displays the first post of every available custom post type? Is it possible to create a loop that goes through all the available custom post types without statically defining what those custom post types are, and then displaying the featured image of the first post for each of those custom post types?
This should work for you: // grab all public post types $post_types = get_post_types( array('public' => true), 'names' ); // loops through each post type foreach( $post_types as $type ) { // setup the query $query_args = array( 'post_type' => $type, 'posts_per_page' => 1 ); // perform the query $items = get_posts( $query_args ); // check if we have found anything if( $items ) { // loop through the items foreach( $items as $item ) { // show the post thumbnail echo get_the_post_thumbnail( $item->ID, 'thumbnail' ); } } }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "custom post types, custom post type archives" }
Why are there two diffrent full screen editors? In the WP editor there is a full screen button. It has shortcut `ALT+SHIFT+G`. When the button is pressed it shows a different full screen editor then when the shortcut is used. I tried this on multiple 3.4.1 installations, one of them had no plugins to interfere. Why is this? **EDIT** its a bug: <
It's a bug < Using the shortcut pulls up the TinyMCE fullscreen editor rather than the custom wordpress fullscreen editor. Update 13. July 2012: Fixed in Changeset 21266.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "wp editor" }
Changing title to lowercase Lets say i have 100 posts. And i would like to lowercase the title. but only 70 of it. I cant use text-transform or mb_strtolower. Is there anyway to download posts and lowercase the title with microsoft word and reupload it?
Assuming this question is related to Wordpress, here is answer :- You can update the titles directly into your mySQL database using simple update function. > one of my user publishs all his posts uppercase (title) i want to edit them and make it normal. – Using some conditional statements as I mentioned in this code, you can restrict the update for particular user(replace 'user_id'). UPDATE wp_posts SET post_title=LOWER(post_title) WHERE post_author = "user_id" This will transform all post titles into lowercase by that user.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "css, title" }
Visual Editor: Paragraph styles appear to one admin but not to others The first admin of my site has a full Visual Editor with style sheets. I create new users who are admins (their profile page has same settings with original admin) but they cannot set the style of paragrpaphs (no drop-down list with styles). Any ideas? Thanks.
1. First of all Check If you disabled the visual editor from your profile page. [See the Screen Shot] !Here is the ScreenShot of Edit Profile Page You ned to **uncheck** the box - Visual Editor, the option is located in User's Edit Profile Page. # UPDATE - 1 2 - You might have been disabled the Kitchen Sink, To enable it Click on small button available in visual editor (Right most button) icon or Press - _**ALT+SHIFT+Z**_ !enable kitchen Sink 3 - Or try switching back to default Wordpress theme (TwentyTen or Twenty Eleven) and check if problem persists.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "editor, css" }
Strange Behavior of Page Template Dropdown My wordpress is updated to latest version 3.4.1 and I noticed a strange function of it - in the Page attributes block page template dropdown has the value: (.*)\n)siU",$template_contents,$template_name) !screnshot Whay this is happening and how to get rid of that?
Here is another similar thread that have been resolved now.. Get name of the current template file Take a look..
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "templates, debug" }
not empty categories don't show in menu I'm trying to resolve a problem i have showing category posts. I have added a category to my main menu, eventhough it has posts - in the basic theme it doesn't show, in my theme - it shows as a link but when i click on it, shows just a blank page. I tried resetting the permalinks, clearing the cache... nothing. Does anyone have an idea what the problem might be. I'm getting a bit desperate. Any help will be greatly appreciated. Thanks a lot in advance
yes i tried both. it was still hapenning. at the end i discovered it was an error coming from the index.php - one line of code i had added following a tutorial which i forgot to remove after. removing it brought everything back to normal. sorry to bother, but it might help someone else.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, pages, get posts" }
How to select a page within admin? How does one apply an action to one particular page within admin? I've added a bunch of wysiwyg editors to one page ("Home") and now I don't need the main editor. But the function below - of course - removes the editor from all pages: function remove_editor_from_home_page() { remove_post_type_support( 'page', 'editor' ); } add_action( 'init', 'remove_editor_from_home_page' ); How can I target the Home page within admin by name - "Home" - or by page_id? This other WPSE answer doesn't want to work for me: Target a certain page within wordpress backend
add_action( 'add_meta_boxes_page', 'wpse_57924_remove_editor' ); function wpse_57924_remove_editor( $post ) { if ( $post->ID == get_option( 'page_on_front' ) /* or hardcode ID if not front page */ ) remove_post_type_support( 'page', 'editor' ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "functions, admin, actions" }
How to reduce the number of revisions? I some posts I have a lot of revisions, and I want only 2 revisions for each post. I found this plugin < that able to set that in the future WP will not store more then 2 revisions, but It does not remove existing revisions. I found this plugin < that can remove all the revisions. But I can not set to leave 2 revisions.
You can use `define ('WP_POST_REVISIONS', 2);` in wp-config.php for two revisions, and you could turn that into your own plugin. Manully remove all revisions with this query run in phpmyadmin: > DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision' and then optimize.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, revisions" }
how to server over http and https with one installation is there an easy way to set up a single wordpress intallation to serve its pages both over http and https? I have an http based website, and I have some pages that I would like to make accessible as facebook pages too. But facebook requires https, and I would prefer to stay with https for normal requests. Do you know a way to share the same page over both protocols? I'm running my wordpress on a webfaction account. Akasha
When you setup the SSL certificate for your domain on your web server, your WordPress site will immediately be accessible via `http / https` connections without any extra configuration. Any configuration is required when you want your website or its backend (`wp-admin` / `wp-login.php`) to load ONLY via SSL (HTTPS). But there's at least one thing you should take care of: * Make sure your canonical URLs are either HTTP or HTTPS only (whichever you want to show up in search results). WordPress SEO by Yoast has an option to enforce this. Not sure, but WordPress HTTPS plugin _may be_ of some help.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "configuration, http, https, customization, proxy" }
remove_query_arg() on rewrite rule I'm attempting to add a `Back to Search Results` link which in essence will simply link back to the starting search page - for example `/?s=test`. I've taken a look at the global query vars and do see there is a `paged` query argument available -- which does do the job when the permalink structure is set to the default - for example `/?s=test&paged=2` run through `remove_query_arg(array('paged'))` corectly becomes `/?s=test`. But, when you visit a second page of search results and you use anything but the default permalink structure - it is not removing `page/2` which is what the default pagination structure outputs. I believe I could just use `$_GET['s']` and append that onto the site URL.. but I figured I'd ask here to see if there is a better way to do this. Thanks!
< was what I was looking for.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "pagination, search, rewrite rules" }
How do I separate my theme's styles from editor styles? Do I need to implement an editor-specific stylesheet for the WordPress WYSIWYG? In doing so will this eliminate style conflicts that I am currently experiencing?I am have not implemented an editor stylesheet so I am noticing that it is becoming very difficult to separate surrounding website styles and editor styles. What's the best way to implement this?
The WordPress editor shouldn't be pulling in the themes CSS files unless you have a file that is named `editor-style.css`. You can either use the editor-style.css and simply place it in your themes root directory, add certain styles to the stylesheet (not all the theme div and id tags will apply to the WordPress Editor). Another way to do it is to use `wp_enqueue_script` to enqueue a CSS file with whatever name you wish, or in a different file location other than the themes root directory. Some authors use this method to minimize the amount of files that live in the theme root directory. If your theme is incorrectly registering or enqueueing a script it can cause the files to be loaded into the WordPress admin area. Let me know what your theme is using for the editor stylesheet if this doesn't help so I can give you better assistance.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "tinymce, editor, css" }
Storing a password for use with a Wordpress plugin I'm writing my first Wordpress plugin which will be a newsletter-type plugin. It'll continuously add members who fill out a form to a database table that keeps track of the following: * cell ID * Time * MemberName * MemberEmail. When I send out the email to the newsletter participants, I want to send it using SMTP. Is there a way I can store a **single** `$smtp_password` in one of my plugin's php files without having it be available to the public? Or maybe store the password in the SQL database, but I don't think creating an entirely new table for it would be necessary, right? How would you store a simple password?
If you store the password in the PHP, it will be accessible to anyone who has the PHP (i.e. anyone who has the plugin). If you store it in the database, it will be accessible to anyone who has direct access to the database (i.e. anyone who installs the plugin and knows how to use phpMyAdmin). However, to store a simple password for a plugin, I'd use a WordPress option. This allows you to easily retrieve the password with code and makes things very flexible. It also allows you to let the user change the stored password if necessary. // Retrieving the password $smtp_password = get_option( 'my_smtp_password' ); // Setting the password update_option( 'my_smtp_password', $new_smtp_password ); Just don't use your regular email password for this. I recommend you set up a dedicated email account for your site to send messages through and keep both the name and password separate from anything you use personally.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "plugins, newsletter, email" }
query multiple posts by id using a string parameter, not array() I'm looking for a way to query posts by id, and using a string as a parameter, instead of an array. Like this: query_posts('p=153'); But I need to get multiple posts. For example with ID 153 and 154. How would I do that with a string as a parameter? The reason that I'm using a string is because I'm generating that string with javascript and if I would do it otherwise it will get super complicated. Any ideas?
You could convert the string to an array using the php explode function. So if you used a comma as your delimiter, you could pass the string `'153,154,87'` and that would and then use the explode function to convert it to array( [0]=>'153' [1]=>'154' [2]=>'87' ) If you want to keep the `p=` you could use str_replace etc.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query posts" }
Only show image from custom field when present How would I adjust the following code to only show the image tag when there is a variable present in the "imageembed" field? <?php $imageid = get_post_meta($post->ID, 'imageembed', true); ?> <div class="newsimage"><img src="<?php echo wp_get_attachment_url( $imageid ); ?>" width="640" /></div>
<?php if (strlen($imageid = get_post_meta($post->ID, 'imageembed', true))) { ?> <div class="newsimage"><img src="<?php echo wp_get_attachment_url((int) $imageid); ?>" width="640" /></div> <?php } ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, custom field, images" }
WP_Query() show posts that end later than today I have a query as follows: $wp_query = new WP_Query( 'meta_key' => 'end_date', 'meta_value' => 'today', 'meta_compare' => '>=', 'post_type' => 'vehicle' ); I want to show only those posts of the vehicle post type that have the meta key end_date which contains a date that is later than today's date. How can this be accomplished?
First, your date format has to be in descending order from largest to smallest units, i.e.: year, month, day, hour, minute, second, etc., otherwise MySQL can't query or order on the field. In this example I use year - month - day: $today = date( 'Y-m-d' ); $args = array( 'post_type' => 'vehicle', 'meta_query' => array( array( 'key' => 'end_date', 'value' => $today, 'compare' => '>=', 'type' => 'DATE' ) ) ): $query = new WP_Query( $args );
stackexchange-wordpress
{ "answer_score": 18, "question_score": 6, "tags": "custom post types, wp query, meta query, date" }
How can I custom order the results from wp_list_categories? I am using wp_list_categories to return (you guessed it) a list of categories within a custom taxonomy. The `orderby` parameter accepts sorting by ID, name, slug, count, and term_group. Is there a way that I can custom sort the results? Ideally I could pass an array of category ID's in the desired order, but obviously I'll have to dig a bit deeper to get this sorted.
There is an unused column, term_order, in the wp_term_relationships table that you can use to assign a custom order to the terms within your taxonomy. The order is set at 0 by default and it will take a custom query to get the order back and another solution to set the order. Example query: function wpse_order_taxes() { global $wpdb; $results = $wpdb->get_results ( "SELECT * FROM $wpdb->terms t inner join $wpdb->term_taxonomy tt on t.term_id = tt.term_id WHERE taxonomy = 'category' ORDER BY term_order ASC LIMIT 0, 10" ); $categories = array(); foreach ( $results as $cat ) { array_push( $categories, $cat->slug ); } return $categories; } This would give you back an array of terms ordered by the custom order.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "loop, sort, order, categories" }
jQuery UI AutoComplete not working in wordpress? To use jQuery UI AutoComplete, I loaded the following scripts: wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-widget'); wp_enqueue_script('jquery-ui-position'); wp_enqueue_style( 'jquery-ui-autocomplete', $ul .'/css/jquery-ui-1.8.custom.css' ); wp_register_script('jquery-ui-autocomplete', $url .'/js/jquery-ui/jquery.ui.autocomplete.min.js', array( 'jquery-ui-widget', 'jquery-ui-position' ), '1.8.2', true ); wp_enqueue_script( 'jquery-ui-autocomplete', $url .'/js/jquery-ui/jquery.ui.autocomplete.min.js', '1.1', true ); After the above scripts, I loaded my own js which includes the following code: $(function(){ $("#to").autocomplete({ // code... }); }); Firebug shows all scripts and style are loaded and gives error message of "$ is not a function". How can I correct this error?
WordPress requires no conflict wrappers for jQuery. (function($){ $("#to").autocomplete({ // code... }); })(jQuery); Or: jQuery(function(){ jQuery("#to").autocomplete({ // code... }); });
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "jquery" }
Yoast SEO: title tags are repeating my website name and slogan I am using the Yoast SEO plugin and I am finding that on my site it is repeating the website title and blog tagline twice. For example, it looks something like this in my browser tab: Example.com | This is my tagline Example.com This is my tagline I have implemented, just as Yoast says, the following code in my header.php: <title><?php wp_title(''); ?></title> Would it also be helpful for me to provide an export of my SEO plugin settings?
`wp_title()` is filterable so there could be another plugin or most likely your theme already adding a filter. Have tried checking the force rewrite in the plugin options? If that doesn't work you need to hunt down what else is adding the filter and remove it. If it's your theme look in functions.php for `add_filter('wp_title', 'some_function_name' );` Remove that line.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "seo, plugin wp seo yoast" }
Finding difference in days I want to store the current time using the update_option and then compare it if the set time was 3 days ago. I want to know in what `format` I should store the time? and then how can I compare it with current time and find the difference in the days?
You should store the time as a unix time stamp then you can use human_time_diff to compare. `echo human_time_diff( get_the_time('U'), current_time('timestamp') );` If the difference is more than 24 hours difference it will return the value in days.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "date time, timestamp" }
Add mark-up after/before link in wp_list_categories This is probably a trivia question, but I can't seem to find a simple solution. This is my wp_list_caterories php... <?php wp_list_categories(array( 'orderby' => 'name', 'show_count' => 1, 'title_li' => '' )); ?> This currently outputs this... <li class="cat-item cat-item-1"><a href=" title="View all posts filed under Uncategorized">Uncategorized</a> (8) </li> I am trying to add this `<span>&#124;</span>` before my link so the final output looks like this... <li class="cat-item cat-item-1"><span>&#124;</span><a href=" title="View all posts filed under Uncategorized">Uncategorized</a> (8) </li> Is it possible to do this within the PHP. I could do it using jquery but I'd rather use the PHP. Many thanks for any help. Josh
one possibility - add a filter to functions.php of your theme: add_filter ( 'wp_list_categories', 'span_before_link_list_categories' ); function span_before_link_list_categories( $list ) { $list = str_replace('<a href=','<span>&#124;</span><a href=',$list); return $list; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery" }
How do I create a column down the right-hand side of my site? How do I create a column down the right-hand side of my site? I changed a setting on one of the pages some time ago, and on that page I have the result that I'm looking for: On this page: < I have a column on the right. But I've forgotten what setting I changed. For example, on this page: < there's no column. I want to create that column on every page.
I can see that you are using the standard Twenty Eleven theme, so all you need to do is go edit the page in question from the admin side, and then if you havent changed the orders of things there, you should have a meta-box with a drop down titled " **Template** ". Choose the " **Sidebar Template** " in the drop down and then save your page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "columns" }
Show different number of posts on second page of category On the first page of a specific category, I want WordPress to show 4 posts per page. On the following pages, however, I'd like to have 6 posts per page. I tried using a conditional query (see below), but this completely screwed up the number of posts per page... $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; if ($paged == 1) { query_posts("posts_per_page=4&category_name=Neuigkeiten&paged=$paged"); } elseif ($paged > 1) { query_posts("posts_per_page=6&category_name=Neuigkeiten&paged=$paged"); } This leads to 3 posts being displayed in a wrong order. There's probably a stupid mistake in there, but I can't figure it out. Echoing the `$paged` variable works just fine.
One way to do it is use WordPress › Custom Post Limits « WordPress Plugins. That plugin gives options for individual categories, first page and pages, archives and search results without needing custom loops in template files.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages, pagination" }
Add on the fly tabs to plugin options Hi I am building a plugin options page. What I'd really like to do is implement repeatable tabs (which I know is possible with the Settings API), but with a twist I haven't seen in any options panel till now. I'd like to create new tabs on the fly, exactly like the 'Menus' section in the admin UI works. Is there any standard way to do this?
WordPress Tabs are non-standard, static html markup. You can only add the markup within your `functions.php` theme file or inside your plugin. <h2 class="nav-tab-wrapper"> <a href="#" class="nav-tab">Tab #1</a> <a href="#" class="nav-tab nav-tab-active">Tab #2</a> <a href="#" class="nav-tab">Tab #2</a> </h2> > !WP Tabs * * * In this helper plugin (WordPress Admin Style) you'll find the class references for the default markup of the admin area. _Full plugin snapshot. The previous snapshot is a detail located at the bottom of this one. Click to enlarge:_ ![full plugin snapshot wordpress-admin-style](
stackexchange-wordpress
{ "answer_score": 17, "question_score": 6, "tags": "options, admin ui" }
Different sql queries count indicator on the main page I use w3_total_cache plugin. But i can`t understand what is going on sometimes. I have enabled database caching and debug info at the bottom. Sometimes on the main page 90-96 db queries, sometimes 495-501. How can be so different results for the same page with the same parameters? Or how can be so much queries sometimes ? What is this meaning? Please explain me:)
Probably some code on your site caches the result of an expensive operation. When the page is cached by W3TC, if on the very same page generation, cache was being regenerated, you will see the actual queries that operation requires. After that, queries are like the usual page load ones. Don't worry about it until you see it too often.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp query, mysql, wpdb, plugin w3 total cache, debug" }
Allowing periods in usernames I have a multi-site installation of wordpress currently running, and I am having some problems with user registration. Currently, I use an external authentication plugin (similar to LDAP i guess) and I use this to validate usernames/passwords. For this to work, every user is first added to the Wordpress list of users, and the plugin checks against this list. The problem is that my organization allows periods inside of a persons username (eg, john.smith). Wordpress is not allowing me to enter john.smith as a username into the system (only allows a-z characters). Is there any type of workaround for this? I would rather not edit the wordpress core as thats a horrible practice
There is a plugin for this. It is Network Username Restrictions Override. Please remember to check out the FAQ #2 to know how to allow periods in usernames. Let me quote it here... > You'll have to update the regular expressions in your .htaccess file if you use email addresses or periods in site URLs. The default WordPress .htaccess configuration does not allow them, nor will this plugin edit your .htaccess automatically due to the risk involved.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "multisite, user registration" }
Autolinking keywords in text with tags Sometimes in my posts I use the keywords that exists in my tags and categories list. Is it possible to automatically link the keywords in texts with the tags and categories? Or should do it manually ? I will use this in my SEO practices. Thank you
Here is plugin that will automatically link to tag / category pages if similar keyword is used in the post. \-- SEO Smart Links
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, tags, seo" }
How to get line breaks to translate to paragraphs? How can I get the line breaks that I make in the TinyMCE editor to translate into new lines in the web page. Suddenly all posts when actually previewed on the theme are walls of text. In the final post's source code there are no surrounding <p> elements surrounding the elements.
By default, line breaks in the TinyMCE editor _are_ convered into `<p></p>` paragraphs. Either your theme or a plugin is disabling this functionality. To figure out which, you need to: 1. Disable all plugins and see if this fixes the problem. * If it does, then re-enable your plugins one at a time to see which one is breaking the paragraph features. 2. Switch back to the default theme (either TwentyTen or TwentyEleven). * If this fixes the problem, then it's your _theme_ that is causing the issue. Ask a new question about fixing your theme and be sure to tell us what theme you're using.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "tinymce, visual editor" }
Wp backend page content not showing, but actual page is fine I'm having a little problem where, well long story short, i get told to "fix" a WordPress gallery etc...be it add/remove images or whatever but when i log in and go to that page, be it in "visual" or "HTML" view, there's nothing in the content area. like i don't see **anything** in there. its blank like if it was a new page. i expect to see something liek short code or you know, something like for example `**[gallery link="file"]**` or something but again, nothing shows on the backend. Now when i go to that same page on the actual live site, and or when i click on the "view page" to preview, the page and its content is show up just fine. Any ideas as to whats going on? Thanks in advanced.
Check the page template setting - is it set to default? If not, look at the code for the template itself. I've seen new WP devs manually insert scripts and codes directly into the template rather than enqueue in `functions.php`. What plugin is being used to manage the gallery?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "dashboard" }
wp_title() empty on a static front page I'm trying to use `wp_title()` to create a heading for my pages, but I'm using a static front page and, while all of the other pages render the title properly, the front page won't. This is what I'm working with: <div id="main-content"> <h1><?php wp_title("", true); ?></h1> <?php while( have_posts() ) : the_post() ?> <div class="pagecontent"> <?php the_content(); ?> </div> <?php endwhile ?> </div> Initially I thought that the front page might be drawing from `index.php`, so I added the same code snippet in there – but, no such luck, the same thing gets rendered – an empty `h1` tag. What's going on here? I want the title of the page to show up in the h1 tag.
### wp_title() is for the html title tags in your websites head section. It's not for outputting a title. Use the_title(), or get_the_title(),
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "filters, title, frontpage" }
Display all months with posts and inside each month show the 5 latest posts I need to display all the months that have active posts, and inside each month I need to display at least 5 posts that are tied to each month.. the HTML will look like this: News items <h6>May</h6> <ul> <li><a href="#">Souvlaki ignitus carborundum</a></li> <li><a href="#">Defacto lingo est igpay atinlay</a></li> <li><a href="#">Quote meon an estimate</a></li> <li><a href="#">Souvlaki ignitus carborundum</a></li> <li><a href="#">Defacto lingo est igpay atinlay</a></li> <li><a href="#">Quote meon an estimate</a></li> </ul> <h6>April:</h6> <ul> <li><a href="#">Sic tempus fugit esperanto hiccup</a></li> <li><a href="#">Epsum factorial non deposit</a></li> </ul> Not sure how I can go about this or what function to use.. any help/direction would be appreciated.
one possibility is to run all posts through the loop and only output the month once per new month: <?php $counter = 0; $ref_month = ''; $monthly = new WP_Query(array('posts_per_page' => -1)); if( $monthly->have_posts() ) : while( $monthly->have_posts() ) : $monthly->the_post(); if( get_the_date('mY') != $ref_month ) { if( $ref_month ) echo "\n".'</ul>'; echo "\n".'<h6>'.get_the_date('F').'</h6>'; echo "\n".'<ul>'; $ref_month = get_the_date('mY'); $counter = 0; } if( $counter++ < 5 ) echo "\n".' <li><a href='.get_permalink($post->ID).'>'.get_the_title($post->ID).'</a></li>'; endwhile; echo "\n".'</ul>'; endif; ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "posts, archives" }
How to deal with small scale comment spam on small commercial sites? When I've built a few sites for small businesses in the past, I've historically been able to do without anti-spam measures. I now have several sites which get maybe between 5 and 20 spam comments a month each. I have it set set so all comments must be moderated, which isn't a really a big deal. I would call it good enough, except the content of these comments is often about Viagra, other drugs, russian porn sites, etc., and I feel like it reflects badly on me having this stuff appear in my clients mailbox, moderation queue, etc.. Akismet could undoubtedly help out with a lot of this stuff - but I can't quite justify the price tag. I try to avoid excessive plugins or bloat, and I feel like there should be a simple solution for this - either a very lean plugin, or a code snippet somewhere. Any ideas?
Use Antispam Bee. It is free, doesn’t phone home, and it works surprisingly well as long as you dont change the comment form too much (you have to test it). Just make sure you disable the mail notification for spam comments. :)
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "comments, plugin recommendation, spam, akismet" }
Where is the content of widgets stored in mysql table I have the cPanel access to a website but no wordpress login info. So I wants to change a widget content in the website. How can I change it through phpmyadmin. Where are that widgets sidebar data actually stored? Is it inside `wp-options` table?
Widget options are stored in the `options` table under `'sidebars_widgets'` as a serialized array. See this post for a longer explanation. !enter image description here Changing the field per PHPMyAdmin is not recommended, use PHP, `get_option()` and `update_option()` instead, WordPress will take care for correct serialization then.
stackexchange-wordpress
{ "answer_score": 21, "question_score": 12, "tags": "widgets, sidebar, mysql" }
slug: should I use latin characters only? I build a legal portal in a non-latin language (Greek). I want all my content to be thoroughly indexed by search engines, preferably in Greek. Should I enter my post slugs in Greek? The pages then appear with URLs ending in %20%32%33 etc instead of Greek. Does this affect the page URLs? Will they be properly indexed by Google? Or should I use latin characters instead? Thanks.
I will agree with King Li. Furthermore there is a very old plugin you can download from my dropbox that is still functional and will be of great help to you. What it does is changing the greek slugs to latin characters (greeklish) automatically for all new posts/pages/custom posts . You will have to manually change your older slugs though. But it is really easy. You just press "Edit" on your slug, delete it and click "Ok". Then, you update your post/page/... To wrap it up, what you do is: 1. Write your titles in greek. (10 + 1 τρόποι για εξοικονόμηση χρημάτων) 2. The slug is turned from greek to greeklish (10-1-tropi-gia-exikonomisi-chrimaton) 3. Finished It is one of the very first plugins we activate on greek sites.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "slug" }
export category and sub-category I'm trying to export a specific category with it's sub-categories. However, Wordpress export option allows either to export all of the categories or to export one specific category at a time. Is there any solution? Thanks.
Workaround: * export all * import on a blank install (e.g.: in your computer) * delete the unwanted ones * export again
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "export" }
Why is get_post_format() for "Standard" returns empty I've enabled custom posts types add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); The default post type is set on `Standard`, and it works for all but the `Standard` type, when I have a standard post the `get_post_format()` return empty. did I miss something in enabling them?
Because "Standard" is not a format itself - it simply implies that the post **has no formats**. > ...which is somewhat deceptive, given it's listed in the Format meta-box as a format to choose I think "standard" quite clearly implies what it means. If you're creating a site in which a post is never "standard", then fallback to a default: if ( ! $format = get_post_format() ) $format = 'gallery'; Alternatively, hook onto `wp_insert_post` and enforce a format if one has not already been set. function wpse_58121_set_default_format( $post_id ) { if ( ! get_post_format( $post_id ) ) set_post_format( $post_id, 'gallery' ); }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 3, "tags": "custom post types, theme development, themes" }
Combo/Drop down box on plugin settings page that allows additional options to be added I'm not sure what this is called and have not had much success searching for it yet. In a plugin settings page, I would like a 'combo box' or 'drop down box' that also includes the ability to add an option that is not currently included. That newly added option would be added to the options in the box from that point on. Is there such a function within the Settings API or does it need a separate text box that is then added to the options array? Or a better way altogether? Thanks :)
If you want to do it dynamically on the page you need javascript. This tutorial explains how to add a items to a `<select>` box. You would have a textbox, the user would type that information in, when they press a button, that would trigger a JavaScript function like the one in the tutorial. Does that answer your question?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin development, settings api" }
Deleting default category in wordpress I'm looking for a way to delete default category functionality in wordpress but after i delete the default category in `wp_terms` table in mysql database, it automatically assigns default category to another category. Does anyone know how to achieve this? Thank you for any help.
Impossible. WordPress _requires_ a default category, that’s hard coded. If you need a taxonomy without default value – create a custom taxonomy.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 4, "tags": "categories, customization" }
Specific mail notification I have a sport site, where every user who registers is a collaborator by default, and when he writes an article, the people I want can approve it. This is what I want: If someone writes an article about soccer (which is a category), only the editors that I want (so every editor which is subscribed in soccer) will receive an email with a link to approve and publish the article. Is there a plugin for it? I'm using Email Alerts, which do the job, but send to everyone the mail.
There is a plugin that _(in my opinion)_ will do just the job for you. It is the "Peter's Collaboration E-mails". You can find it in the WordPress plugins repository. From the plugin's description: _"You can create groups of Contributor users and assign different moderators for each group. In other words, different users can be notified based on who wrote a post. You can also assign moderators based on various taxonomies (such as tags, categories, and more) on post, pages, and custom post types. If a Contributor user belongs to multiple groups and/or a post has multiple taxonomy values, all moderators who have been assigned to the relevant groups or who match the post type rules are e-mailed."_ I hope that helps.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugin recommendation, email" }
Create a Metabox that behaves Like a Taxonomy Box I need to show all my custom articles on an archive page but grouped/sorted by subject. So that the result is somewhat like Subject A: * A Sample Post * Another Sample Post Subject B: * List item A Post About Bacon and so on? I've read some related posts on here 17155 and 14306 and have come to the conclusion that this type of grouping must be done with post meta. However a simple metabox with a text input isn't as friendly as the checkboxes of the category metabox.... nor the tag box with its (choose from most popular tags option). So I am looking for advice, what is the best way to get the best of both worlds? I'd like to enforce selection into only 1 subject, but I'd like to be able to see what other subjects have already been used. Can I replace the category metabox so that it uses radio buttons instead of checkboxes and then save the category info as post meta on save? where to start?
i ended up building a plugin that enforces radio buttons for any taxonomy. < for the project in question i will probably also save the taxonomy as meta. sucks that i need/want half the ability of taxonomy (knowing other available terms, etc), but need the sorting by meta.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "post meta" }
w3 total cache minification breaks wp_localize_script() I am trying to configure W3 total cache plugin to speed up my site. The minify option is great but I am running into the following issue: Let's say I have a JavaScript file I am attached `wp_localize script()` to and it's called `'additions.js'`. Because W3TC minifies this JavaScript file and renames it, the `wp_localize_script()` function no longer sees my `'additions.js'` file and the variables inside it don't get shared with it. Does anyone have a solution for this? Let me know if anything is unclear.
W3 Total Cache has 4 locations to include the minified files. Since `wp_localize_script()` hooks into `wp_head()` (unless you specify in footer in your enqueue) you can use the `before </body>` minify location and your script will have access to the variables set. On some occasions this has failed for me so I just exclude the script from minify.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 5, "tags": "plugin w3 total cache, wp localize script" }
How to replace bloginfo(template_url) Basically I've used `bloginfo(template_url)` in a WordPress theme, but when I run theme-checker, it recommends to replace `bloginfo(template_url)` with `get_template_directory_uri()`, however when I use `get_template_directory_uri()` it doesn't work. It works fine if I use it to replace `get_bloginfo(template_url)` but that's not what I want now. Is `bloginfo(template_url)` being deprecated? If it is, what is it's replacement? Thanks
`bloginfo($option)` echos out a value whereas `get_template_directory_uri()` returns a string - did you maybe forget to echo `get_template_directory_uri()`? Also are you passing a string with quotes i.e. `bloginfo(template_url)` vs `bloginfo('template_url')`? Both `bloginfo('template_url')` and `get_template_directory_uri()` should work, they aren't deprecated.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "deprecation" }
How to localized one js file for different actions? I have a group of javascript functions in one js file. each function acts on a specific action and get its own ajax response. some are on different pages, some are on the same page. If I don't do the localize, I can't get response. How can I localize this file for multi actions?
Maybe I got your question wrong. I don't get what you mean by: > If I don't do the localize, I can't get response. But in general, this function lets you localize your JS strings, but you can also use it to set JS variables: function set_my_js_var() { // logic here for setting the right JS var return "some value"; } function load_fe_scripts() { wp_enqueue_script( 'global-js-var', get_template_directory_uri() . '/js/my_file.js' ); $localize_array = array( 'my_js_var' => set_my_js_var() ); wp_localize_script( 'global-js-var', 'my_global', $localize_array ); } add_action('wp_enqueue_scripts', 'load_fe_scripts'); You can now acces the var in you JS File by `my_global.my_js_var`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "ajax, javascript" }
WP Customer Reviews - shortcodes **WP Customer Reviews Plugin** Looking for some **shortcodes** for displaying the **review form only** / **reviews only**. On the plugin page there is an info about shortcode ( _Shortcodes available for inserting reviews and review form on any page or widget_ ), but I cannot find theme anywhere. < Have you got any experiences with the plugin? Any suggestions much appreciated.
The plugin registrer some shortcodes in wp-custom-reviews.php: add_shortcode( 'WPCR_INSERT', array(&$this, 'shortcode_wpcr_insert') ); add_shortcode( 'WPCR_SHOW', array(&$this, 'shortcode_wpcr_show') ); Try: `[WPCR_INSERT]` and `[WPCR_SHOW]`
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "plugins, review" }
Add Post type menu to another menu I've created a menu page in the dashboard, then I created a custom post type and now I want to put the menu of the custom post type as a submenu under the first menu page I had created. I tried 'show_in_menu' => 'admin.php?page=mytestpage', However that did not work. Any tips?
Ended up creating the custom post type and adding my custom page as sub page to that, as suggested by Bainternet
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "custom post types, admin menu" }
rename index or homepage I've tried about anything but I can't seem to get it to work how I would like to so I hope you can help me out. Situation. I have 2 wordpress websites, running on different hosts, only link is a 'commercial' links. they are set up like this. url.com/wp is my wordpress directory, with my index in root. referring. So I have pretty url url.com/contact etc. Now I have a simple html page which has to be a selector. When you go to url.com and url2.com you see this index.html which links to url.com and url2.com. so each root page of the urls , the user can choose to go to url 1 or 2. I can't change my hostings first file to go to, to take index.htm before the index.php of wordpress. .htacces using DirectoryIndex didnt do the trick either. So I would like to rename my index.php from wordpress to something else. But then it just breaks... I hope I'm clear enough about it. It's a 'simple' problem but kind of hard to explain for me. Hope you can help me out.
You're creating a loop that you can't break out of ... I think what you are saying is you want a visitor to go to `domain1.com/index.html` and then choose to go to `domain1.com/index.php` (Wordpress CMS) or `domain2.com/index.php` **Static Homepage in WordPress** You're best off to create a Static Homepage in WordPress and have links on this to either `domain1.com/what_ever_page_is_your_blog` You can also create your own custom landing page template which is then published from inside WordPress. **Move all Wordpress files including index.php to sub-folder** The easier approach would be to just move all the wordpress files into a sub-folder like `domain1.com/wordpress` This way you can have visitor go to `domain1.com/index.html` and chose to go to `domain1.com/wordpress` or `domain2.com`
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, homepage" }
How to change amount of categories listed on dashboard? I have 100+ categories & sub-categories for a site I'm working on. How can i change the amount displayed in the list of categories (default 20 per page) on the dashboard?
You can set this using the Screen Options tab at the top of the category edit screen: !enter image description here
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "categories" }
Disable adding of new post (custom post type) How do I disable adding of new posts of a particular custom post type? Found this code in Log Deprecated Notices plugin: $screen = get_current_screen(); if ( self::pt == $screen->id && ( $screen->action == 'add' || $_GET['action'] == 'edit' ) ) wp_die( __( 'Invalid post type.', 'log-deprecated' ) ); if ( self::pt != $screen->post_type ) return;
As per this answer, the "correct way" is: register_post_type( 'custom_post_type_name', array( 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => false, // Removes support for the "Add New" function ( use 'do_not_allow' instead of false for multisite set ups ) ), 'map_meta_cap' => true, // Set to `false`, if users are not allowed to edit/delete existing posts )); \-- ~~ add_action( 'load-post-new.php', 'wpse_58290_disable_new_post' ); function wpse_58290_disable_new_post() { if ( get_current_screen()->post_type == 'my_post_type' ) wp_die( "You ain't allowed to do that!" ); } Note that you'll also need to hide the UI elements, such as in the menu, and the "Add New" button in the `h2` tag on the edit screen. ~~
stackexchange-wordpress
{ "answer_score": 9, "question_score": 2, "tags": "custom post types" }
Opening all posts for comments Is it possible to use the user-interface (front-end) part of Wordpress to open comments on all posts in one (or two) clicks? I have many posts with closed comments which must have happened by mistake, and I want to make them all open comments. Here's the caveat: My host provider doesn't give me `ssh` access into the database, so I can't just run a simple sql `REPLACE` command. Therefore, I need a way to do this from the Administration Panel within wordpress. Thanks!
I wrote up this quick plugin that updates all posts of type `post` to `comment_status` `open` on activation, it should work for you. you can immediately deactivate and delete it once you activate it that once. <?php /* Plugin Name: update comment status */ function activate_update_comment_status() { global $wpdb; $wpdb->update( $wpdb->posts, array( 'comment_status' => 'open' ), array( 'post_type' => 'post' ), array( '%s' ), array( '%s' ) ); } register_activation_hook( __FILE__, 'activate_update_comment_status' );
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "comments" }
How go give $value to wp_query Probly easy question but just cant seem to find whats wrong. I cant build a query based on a search when i use ' ' but not when i use a alrdy declared variable. This works $query2 = new WP_Query( 's='motorkap met' ); while( $query2->have_posts() ) { $query2->the_post(); echo the_title();?> </br> <?php } This doesnt for some reason.... I cant seem to find how to pass the already declared variable $zoekterm = removeCommonWords('motorkap met'); $query2 = new WP_Query( 's=$zoekterm' ); while( $query2->have_posts() ) { $query2->the_post(); echo the_title();?> </br> } Very stupid I know but been searching for over 2 hours alrdy :( must be passing it wrong somehow tried everything from echo, to just $zoekterm to 's='$zoekterm' ' etc...
Assuming `removeCommonWords()` returns a string, you can do the following: $zoekterm = removeCommonWords('motorkap met'); $query2 = new WP_Query( array( 's' => $zoekterm ) ); while( $query2->have_posts() ) { $query2->the_post(); echo the_title() . '</br> '; } Sometimes the array notating is more useful than the string notation ...
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query" }
Create Mashable Follow-like Facebook, Twitter login/connect? Hi want to ask if anyone can share an idea on how Mashable registration works? Basically the only option you have to register to their site is by Facebook or Twitter, after you login to one of them it automatically create a wp_user. No more Wordpress login/Regs needed. I know many plugins like _Simple Facebook/Twitter/Google connect *_ are available, but i haven't found any plugin related to this one like Mashable have. If anyone can help me on this that will be great. [*] : Simple Facebook Connect, Simple Twitter Connect, Simple Google Connect — by Otto
Mashable Follow is custom built for Mashable.com, so you won't find a plugin that brings that level of integration to your WordPress site. That said, there are two that _may_ suit your purpose: * **Social:** Integrates your WordPress site with social networking sites Twitter and Facebook, thereby offering a whole lot of features including—automatically broadcasting posts to the social networks, comment login, pulling in reactions from each (replies, retweets, comments, "likes") as comments, etc. This plugin is very well coded, and maintained. * **WordPress Social Login:** A new plugin in its first public release, supports some 20 social networks. The plugin is built on top of Social Connect plugin and HybridAuth Library
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "facebook, twitter, authentication, wp login form, wp user query" }
Warning: urlencode() expects parameter 1 to be string, array given I have posted a question on StackOverflow (sorry for the cross link) and while I'm striving to find a solution to this, I stumbled across this warning : > Warning: urlencode() expects parameter 1 to be string, array given in /var/www/.../httpdocs/wp-includes/formatting.php on line 3192 And doing a backtrace, I find it originates in `query.php` : **wp_includes/query.php** , _lines 1710...1712_ if ( isset( $t->rewrite['hierarchical'] ) && $t->rewrite['hierarchical'] ) { $q[$t->query_var] = wp_basename( $q[$t->query_var] ); } Now, I get this error because one of my URL param is an array of categories, where I'm trying to search and return all product (custom post type) that has one or more of the defined categories assigned. Why is WordPress trying to call `basename` on an array of `GET` parameter is beyond me. Anyone care to explain this to me? Thanks!
I'm not sure exactly what's happening, but I can guess based on a few context clues. That particular function is `parse_tax_query`. It appears to be checking if the taxonomy is hierarchical, I assume it's expecting a string that could possibly be a parent/child path of terms, so it uses basename to get the actual term queried- the next line is `$term = $q[$t->query_var];`
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "wp query, warnings" }
Exclude pages by menu order i have a "Default Page Generator" on theme activation i have created... in that file i set 'menu_order' for each page. **i want to exclude pages with menu order bigger then 50 from the default wp_list_pages menu** Is there a way to check for / retrieve 'menu_order' of each page? and if there is can you think of a way to intergrate it into the wp_list_pages function?
Declare the following function in your functions.php function wpse58346_wp_list_pages( $pages, $r ) { foreach( $pages as $key => $page ) { if ( 50 < $page->menu_order ) unset($pages[$key]); } return $pages; } Now before calling `wp_list_pages()` apply a filter as follows add_filter('get_pages', 'wpse58346_wp_list_pages', '', 2); And after you have called `wp_list_pages()` you can remove the filter so that it doesn't mess with some other funcctionality remove_filter('get_pages', 'wpse58346_wp_list_pages');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "pages, wp list pages, exclude, menu order" }
How to add custom css file in theme? Some themes ask you not to edit the style.css file, instead use custom.css file. If you write code on custom.css, it will overwrite the same element style in style.css. I think this is done in order to prevent the loss of user styles on theme update, is it so? **How this works?** Do they already include custom.css file in their theme? But how this file is included in the theme so that he theme look for style in custom.css first? Thanks.
I usually add this piece of code if I want to add another css file <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/my_custom_css.css" type="text/css" media="screen" /> I believe the theme makers want to retain as much as possible of the theme's layout design. So a custom css file doesn't hurt much. I think it's more of a support question. With custom css file, the makers can help those who use their themes more easier. Because the original style.css is unaltered, so the theme maker can probably take a look in the custom css file.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 21, "tags": "theme development, themes, css" }
get_image_tag() html output : empty src attribute I'm trying to use the `get_image_tag()` function to alter the html output of an image, like so : add_filter('get_image_tag', 'kh_image_attachment', 10, 5); function kh_image_attachment($html, $id, $alt, $title, $align) { $html = '<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="' . esc_attr($img_src) . '" id="'.esc_attr($id).'" alt="' . esc_attr($alt) . '" title="'.esc_attr($title).'" class="'.$class.'" onload=lzld(this) onerror=lzld(this) />'; return $html; } Unfortunately, the `src` attribute remains empty (the class attribute as well, but I couldn't care less about that). I can't for the life of me figure out why. Can you help me out here? Thank you.
# Solution: I needed to use the `wp_get_attachment_image_src` function. add_filter('get_image_tag', 'kh_image_attachment', 10, 5); function kh_image_attachment($html, $id, $alt, $title, $align) { $image_source = wp_get_attachment_image_src( $id, 'full' ); $html = '<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="'.$image_source[0].'" id="kh-image-attachment-'.esc_attr($id).'" alt="' . esc_attr($alt) . '" title="'.esc_attr($title).'" onload=lzld(this) onerror=lzld(this) />'; return $html; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, images" }
wp_editor on custom meta textarea field - images and html fails So I have made some custom textareas on my frontpage template. This works fine and I can safe content and so on... But I am experiencing some issues. When I click "Upload/Insert" I can work with the dialogue - but when I type insert the dialogue closes but no image is inserted into the textarea... The other issue is with the to tabs "visuel" and "HTML". I cant click on the "HTML" tab... nothing happens... I get the following javascript error: vta is null anonymous() anonymous() onclick() event = click clientX=1523, clientY=145 qtrans_save(vta.value); I call the wp_editor with: wp_editor( $meta, $field['id']); The field ID's are unique and currently using _ like 'custom_frontpage_textarea3'. I have tried without the _ but that had no effect. Any ideas?
Not saying it's not possible, but wp_editor is not designed to be used in a meta box (when tinyMCE, which is on by default, is activated). Here's the trac ticket where some of the issues are discussed. You can however, use the actions `edit_page_form` or `edit_form_advanced` to add your editor with tinyMCE, as suggested by azzoz, or, use the HTML only editor, as suggested by nacin. Edit: Here's an example of adding the editor with tinyMCE disabled: wp_editor( $meta, $field['id'], array ( 'tinymce' => false ) ); I tested it by adding 2 editors and was able to insert media into each editor using the insert into post button. If you can do without tinyMCE, then this is probably the way to go. Otherwise, you'll need to add your editors using the hooks mentioned above.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, wp editor" }
Remove rows in the manage post/page view I'm looking for a way to remove the rows with the title, date and other stuff that's shown on the manage posts/pages screen (highlighted with red in the image below). I know that I could easily hide it with css, but I'm wondering if it's possible to do it without css and hacking core files. !Visual description on what I want to remove
I'm gonna post the CSS anyway because this is the best way to hide it. table.pages thead, table.pages tfoot { display:none; } I didn't find any useful hooks in the source that would allow to pull the actual HTML for the table header and footer out.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, posts, admin, wp admin" }
PHP Widget and do_shortcode I'm using PHP Widget which allows PHP code to execute from a widget. I tried using this code to execute do_shortcode but it's not rendering <?php $lat = get_field('woo_maps_lat'); $long = get_field('woo_maps_long'); echo do_shortcode('[forecast location="' . $lat .','.$long. '" measurement=\'C\']'); ?> If I echo a variable with simply `echo $lat;' it works. So the PHP Widget is working fine. The problem is echoing the shortcode in the widget. I can add shortcoded just fine to a widget but I need to be able to add the php variables where they are. I tried adding `add_filter('widget_text', 'do_shortcode');` to my functions.php but it's still not rendering properly. Any suggestions? Thanks
The problem was the double quotes which are needed in normal shortcode usage in posts and pages for some reason when using do_shortcode the double quotes in the attributes where breaking the function. Working code below <div> <?php $lat = get_field('woo_maps_lat'); $long = get_field('woo_maps_long'); echo do_shortcode('[forecast location=' . $lat .','.$long. ']'); ?> </div>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, widgets, shortcode" }
Where is the /blog/ url set from? I'm having a weird issue while setting up a site. It almost seems as though the /blog/ url is reserved or already in use, only it isn't as far as I can tell. I setup a new page called 'Blog' and set the permalink to '/blog/'. Then under 'Settings' => 'Reading' I set the Posts page to be 'Blog'. Then I went one step further and setup a new template called 'tpl-blog.php' and assigned it to the 'Blog' page. After all that I entered some content in and it and tested and it didn't look right, none of my text was in there and a lowercase 'blog' was showing up for the title. I tested a bit more and found it was using the page.php file instead of my custom tpl-blog.php. Thanks for any help! Levi
Change the filename from `tpl-blog.php` to `page-blog.php`, see if that fixes it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "templates" }
How to make website with many template that active I want to make a website with wordpress engine but with some features. One website has 3 template and every template is active because I want to make 1 website that has 3 sub categories such us blog, portfolio, and photo gallery but with different templates and fitur in every sub-category. Anyone knows how to do that, please ? Thank you very much in advance.
Yes it is possible to create templates for different categories and tags for posts you can also use a plugin like this < If you look at (for example) < \- then their free theme it already has a blog, portfolio and photo gallery templates for you. This might help you to see what is possible with WordPress.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "theme development, themes" }
Customizing Default Categories Widget I am trying to hack the default categories widget from wordpress. I have the categories displaying the way I want but I am having trouble editing the output. The widget shows the number of posts in each post which is what I want, but it also displays the number in parenthesis. I don't want that. I know how to get rid of them but I can't seem to make it work. I tried like so $cat_args['title_li'] = ''; $list = wp_list_categories(apply_filters('widget_categories_args', $cat_args)); $list .= str_replace('(', '<span class="number">', $list); $list .= str_replace(')', '<span class="number">', $list); echo $list; It just continues to display the categories the same way. I don't understand why it's not echoing the list. I am using the code for the categories from the default-widgets.php file in the wp-includes folder.
`wp_list_categories` echoes output by default, your `str_replace` isn't working because nothing was assigned to `$list`.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 3, "tags": "categories, widgets" }
How to search in two different wordpress blogs by using a single searchform? How can i get search results from two different blogs [ www.mysite.com and www.blog.mysite.com ] using a single search form.
It depends on the setup; if they are setup as multisite, check this plugin: Multisite Global Search If that doesn't work, I'd try custom Google search. They should allow you to search on both sites.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "search" }
How to show customized activity for custom post types in buddypress activity loop? I'm building a city portal/ social business directory with buddypress and wordpress. All business listings are stored as a custom post type called 'business'. I'm using the following code to show the activity related to business listings in the activity stream function bbg_record_my_custom_post_type_comments( $post_types ) { $post_types[] = 'business'; return $post_types; } add_filter( 'bp_blogs_record_comment_post_types', 'bbg_record_my_custom_post_type_comments' ); this is the result Right now it says > user commented on the post 'postname' While I need it to say > user wrote a review on 'postname' for the business post type, and > user commented on 'postname' for other post types. Any help is greatly appreciated.
You can filter on the action before it is saved by using add_filter on 'bp_blogs_activity_new_comment_action' as shown in bp-blogs-functions.php -> bp_blogs_record_comment() Or you can filter before the action is displayed by using add_filter on 'bp_get_activity_action' Probably better to do the former because you can easily check post->post_type to see if it is 'business'. This shows how to adjust the activity action for the creation of a CPT: < You should be able to adjust that to handle comments.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, buddypress" }
Disable visual editor on one specific page I would like to remove the visual editor from one specific page because if I edit this one page in Visual mode, it breaks the code. I want to make sure the client doesn't have this option on the particular page. However, I don't want to remove the html editor. This line of code removes the visual editor and the html editor: remove_post_type_support('page', 'editor'); a closer look at remove_post_type_support: < But I want to only disable the visual editor. Initial testing, in functions.php for this theme, I have: function remove_editor_init() { if ( is_admin() ) { if (is_page(2548)) { remove_post_type_support('page', 'editor'); } } } add_action('init', 'remove_editor_init'); However, the conditional statements is_admin() and is_page() don't seem to working together. Any suggestions?
In your code, calling the action `admin_init` makes `is_admin()` unnecessary. And, if not mistaken, `is_page()` is meant to be used in the front-end... But the solution is the following (based on this Answer): add_filter( 'user_can_richedit', 'wpse_58501_page_can_richedit' ); function wpse_58501_page_can_richedit( $can ) { global $post; if ( 28 == $post->ID ) return false; return $can; }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "functions, pages, visual editor" }
trim custom field text value and show (...) I am using this code here: <?php $trim_length = 25; //desired length of text to display $custom_field = 'my-custom-field-name'; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { echo rtrim(substr($value,0,$trim_length)); } ?> It works - but I would like to have a "(...)" at the end of the trimmed text. And _only_ if the value really was trimmed. I used `if ($value) { echo rtrim(substr($value,0,$trim_length)) . '(...)'; } ?>` But this makes the "(...)" at the end of every text from custom field.. Thank you! AD
building on keatch's answer you only need to trim if its longer the 25 chars so: $trim_length = 25; //desired length of text to display $custom_field = 'my-custom-field-name'; $value = get_post_meta($post->ID, $custom_field, true); if ($value) { if (strlen($value) > $trim_length) $value = rtrim(substr($value,0,$trim_length)) .'(...)'; echo $value; }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "custom field, meta value" }
How do I remove the page listing menu in the header in the Twenty Ten Theme? How do I remove the page listing menu in the header? I would like just the choosen header picture to show up without a listing of all of the pages on the site listed underneath. Also at the very top or the page it displays the domain and title above the header. What is the best way to eliminate that and just have the header picture hug the top of the screen? I and using the free theme Twenty Ten. Thank you in advance.
there is a simple fix and that is removing line 103 in the themes header.php file but next time you update the theme it will return so to make you change permanent and still enjoy the updates first Create a child theme and then overwrite the header.php file in your child theme. its sound hard but its really not: First create a directory in your themes directory eg `my_theme` Then create a new file named style.css and add this to it. /* Theme Name: Twentyten Child Description: Child theme for the twentyeleven theme Author: Your name here Template: twentyten version: 0.1 */` @import url("../twentyten/style.css"); and last copy the header.php file from the `twentyten` directory to your `my_theme` and then remove line 103 from it (in your new theme directory).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme options" }
favicon now showing up I have wordpress installed in the /home directory on my server, so it was set up that you would have to go to www.mywordpress.com/home to see my wordpress and just going to www.mywordpress.com would take you to a different homepage. Well, I went into my setting and change the Site Url so to www.mywordpress.com so that my wordpress would be my homepage. Today, I tried to setup a favicon and it only works if the url is www.mywordpress.com/home/whatever even if you try going to www.mywordpress.com/whatever. If the /home isnt in there the favicon doesn't show up. I have the code pasted in my header.php template Thanks!
If you have put the code in your header.php is the full URL to the Favicon correct? Also check in another browser as Favicons can be heavily cached (so check another machine) I'm assuming the non / page (without home) has the favicon code present on it as well? What is URL?
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "favicon" }
Generating the ogp tags in theme I use to generate the ogp tags in themes I code but this commercial one is beyond my knowledge. The client want to share a page but any image option shows up. Instead of a `taxonomy-name.php` template file, this theme rely on a page templates, where user choose the category/taxonomy to display the gallery from. Problem is: I can't get the attachments as the gallery renders after the query, I do will ask the theme autor to implement this but right now I need to fix this some way. **Info** * Page template * Theme in question
If it is a `page` the global `post` object is already set when `wp_head` fires. But you have to get the data for this page with custom code. Pseudo code: add_action ( 'wp_head', 'wpse_58539_get_ogp' ); function wpse_58539_get_ogp() { if ( ! is_page_template( 'your-template-name' ) ) { return; } $page = get_post( $GLOBALS['post'] ); // Inspect the page meta data to find the taxonomy and the images. // print the OGP data return; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "themes, tags, facebook, open graph" }
Website not listed under Sites (in a Network environment) I have a Wordpress network installed, and the first website I created is not listed under the Sites entry in the top horizontal menu. The second website I created is, along with the parent website. If I go to Network > Sites, the first website is listed, and I can use the website fine, provided I type in the URL directly into the address bar. Do you know the best method to add the site back into the Sites menu entry at top?
I found the cause. Under Network > Sites, there were no users listed next to the website in question. My user account was listed next to the other two websites. So, adding my user account as an administrator of the website added it back to the Sites menu. I am not sure why my user account was not an administrator already.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, network admin" }
the_post_thumbnail call removing li in code Need some help here. I've been working on a widget to display a list of featured posts (custom post type) and want to display the featured image for each post so I was using the_post_thumbnail call with a custom thumbnail size included as the parameter and for some strange reason, the call is removing some of the HTML that is in my echo'd string output from the widget. Below is the line that I am calling: echo ' <li>'. the_post_thumbnail('talent-featured-thumb') .'</li>'; This is the HTML that is rendered: <img width="225" height="127" src="PlaceHolder.png" class="attachment-talent-featured-thumb wp-post-image" alt="3MGPlaceHolder" title="3MGPlaceHolder" /> <li></li> Any help?
`the_post_thumbnail();` function is not supposed to be `echo`-ed! `get_the_post_thumbnail();` is meant for that. Refer to the linked WordPress Codex pages. **Try this instead:** <?php // Wraps post-thumbnail in li tags echo ' <li>' . get_the_post_thumbnail('talent-featured-thumb') . '</li>'; ?>
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "custom post types, widgets" }
Send Email to Users after Deleting Account It is possible send email for deleting account on wordpress?? Like this: Ok after click send email to user with ex text: "your account has been deleted" ??
Yes. The full answer is here in the codex: < ~~So I won't repost its code.~~ function my_delete_user($user_id) { global $wpdb; $email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE ID = '" . $user_id . "' LIMIT 1"); $headers = 'From: ' . get_bloginfo("name") . ' <' . get_bloginfo("admin_email") . '>' . "\r\n"; wp_mail($email, 'You are being deleted, brah', 'Your account at ' . get_bloginfo("name") . ' is being deleted right now.', $headers); } add_action( 'delete_user', 'my_delete_user');
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "users, email, account" }
line break are not working when editing a post So I have a problem when making a post. If I press enter and make a new line in the editor and press safe the line break diapers. But when I show the post it have inserted a line break. So somehow the editor is not able to show the line break? If I save the editor again the line break disappears from the post as well. Any ideas? I read in a post to try and use: remove_filter ('the_content', 'wpautop'); remove_filter('the_content', 'wptexturize'); Which I did and now line breaks don't work at all. I have build a custom page where the posts are shown with the echo the_content();
Ah sorry I just realized that I had margin: 0 on all elements to reset all defaults in browsers... this caused the issue!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 3, "tags": "editor, line breaks" }
Insert Ad Code in the Middle of a Post I want to insert an ad code in the middle of a post via `functions.php`. I found several links but either they don't use `functions.php` or don't insert the code in the middle. Can anyone tell me how to do this? Also, I don't want to use a plugin.
This function inserts your ad code after the specified paragraph. add_filter('the_content', 'wpse_ad_content'); function wpse_ad_content($content) { if (!is_single()) return $content; $paragraphAfter = 2; //Enter number of paragraphs to display ad after. $content = explode("</p>", $content); $new_content = ''; for ($i = 0; $i < count($content); $i++) { if ($i == $paragraphAfter) { $new_content.= '<div style="width: 300px; height: 250px; padding: 6px 6px 6px 0; float: left; margin-left: 0; margin-right: 18px;">'; $new_content.= '//Enter your ad code here....'; $new_content.= '</div>'; } $new_content.= $content[$i] . "</p>"; } return $new_content; }
stackexchange-wordpress
{ "answer_score": 19, "question_score": 3, "tags": "functions, the content" }
Redirect user to a custom url after submitting the comment After someone submits a comment this line of codes redirects him to the post (i believe). Can I modify the code in order to redirect him to a custom URL? do_action('comment_form', $post->ID) Ty for the answer, UPDATE: my comments.php <form> ....... <input name="submit" type="submit" id="submit" tabindex="5" value="Submit" /> <input type="hidden" name="my_redirect_to" value=" /> <?php comment_id_fields(); ?> <?php do_action('comment_form', $post->ID); ?> </form> my functions.php add_action('comment_post_redirect', 'redirect_to_thank_page'); // Redirect to thank you post after comment function redirect_to_thank_page() { if ( isset( $_POST['my_redirect_to'] ) ) return $_POST['my_redirect_to']; } The code does not work, it's not redirecting to google.com for example. Any ideas why? Ty
Not quite; the redirect occurs inline inside `wp-comments-post.php` Use the filter `comment_post_redirect` to pass back any URL of your choice. Arguments passed are the default redirect & comment object, respectively. Based on your comments, here's a suggestion: function wpse_58613_comment_redirect( $location ) { if ( isset( $_POST['my_redirect_to'] ) ) // Don't use "redirect_to", internal WP var $location = $_POST['my_redirect_to']; return $location; } add_filter( 'comment_post_redirect', 'wpse_58613_comment_redirect' );
stackexchange-wordpress
{ "answer_score": 8, "question_score": 6, "tags": "comments" }
Replace do_action() with a normal submit form in comments.php In my comments.php I have this code: <input name="submit" type="submit" id="submit" tabindex="5" value="Submit" /> <?php comment_id_fields(); ?> <?php do_action('comment_form', $post->ID); ?> Is there a way to replace this code whit a simple submit form? and not use: do_action() ?
Try this: <?php comment_form(); ?> **References:** * Function Reference for `comment_form();` on WordPress Codex * `comment_form();` WordPress function reference, arguments and source at QueryPosts
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "comments" }
Validate emails in array using foreach How do I validate an array of emails from a textbox before sending them to the `wp_mail()` function? $emails = '[email protected];[email protected] [email protected],[email protected], email5.com'; $emails = preg_split('/[;,\n]/', $emails); $validEmails = array(); $subject = 'Hey Subject'; $message = 'I am a message'; foreach($emails as $key=>$value){ if (is_email($value)) { array_push($validEmails, $value); } } wp_mail($validEmails, $subject, $message, $headers); The sample code above stops on the `if (is_email())` condition. How can I validate each email in the array whichever way before sending to the mail function?
Are you aware you can pass a comma-separated string of email adresses to `wp_mail`? // Make sure your email strings only uses comma as a separator $emails = preg_replace('~[,;\s]+~', ',', $emails); Then just throw that string into `wp_mail`’s first argument. Depending on exactly what you want to do with the emails, this approach may be sufficient. The `wp_mail` function internally relies on the PHPMailer library (unless you use a redefined `wp_mail` function). PHPMailer validates the email before adding it to the recipient list. Invalid emails will be skipped.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "php, wp mail" }
Is it possible to integrate a custom login feature with wordpress? I'm looking for a way for members of my site to be able to post comments on the site's wordpress blog, and have their name and avatar from the site show up next to their comments. Is there a way to link wordpress to the site's custom login system to let the members of my site login and be able to post from their names and avatars? Anyone?
There are lots of plugins to do this. It sounds like you're looking for JetPack's rather new comment module. There are also powerful commenting plugins like Disqus and LiveFyre.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, login, authentication" }
Way to check if we are in Theme Customizer mode? > **Possible Duplicate:** > How to execute conditional script when on new customize.php (Theme Customize) screen Is there a Conditional Tag, or any other method, that we can use to check if we are customizing the theme? I want to include some extra stylesheet while customizing the theme. so I'd like to have sth like: if ( theme-customizer-is-active ) { // load some extra styles }
As in this question: How to execute conditional script when on new customize.php (Theme Customize) screen global $wp_customize; if ( isset( $wp_customize ) ) { // do stuff }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "conditional tags, theme customizer" }
How to use get_categories() with Event Organiser plugin I want to display my categories in tabs. All is good, except my "Upcoming Events", created with Event Organiser (awesome plugin at < are not being treated like a normal category, so they don't appear. In essence, get_categories() is not returning the events category. How can I fix this display? $args = array('type'=> 'post', 'order' => 'ASC', 'hide_empty' => 1 ); $categories = get_categories( $args ); foreach($categories as $category) { echo '<li><a href="#tabs-content-'.strtolower($category->term_id).'" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></li>'; array_push($cat_list,"$category->term_id"); }
Event categories are terms in a custom taxonomy, 'event-category', so you should use `get_terms` instead: //Args for which terms to retrieve $args = array('type'=> 'post', 'order' => 'ASC', 'hide_empty' => 1 ); //Array of taxonomies from which to collect the terms $taxonomies = array('event-category'); //Get the terms $terms = get_terms( $taxonomies, $args); //loop through the terms and display foreach($terms as $term) { echo '<li><a href="#tabs-content-'.strtolower($term->term_id).'" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a></li>'; array_push($cat_list,"$term->term_id"); } If you want to get terms for both the 'category' and 'event-category' taxonomy then you can add 'category' to the `$taxonomies` array.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "plugins, categories, events, plugin event organiser" }
Multiple areas of dynamic content in a page I am new in Wordpress and what I really can't find how to do is the following: I have a new Page created from the CMS. This pages have different modules with text. Take for example this template < There are three modules in the row with an icon, a heading and text. And below other four. How is possible so user be able to edit from wordpress each one of these modules separately?
The example you gave has a listing of three pages and four posts (which are dated). The same can be achieved by one of the following: 1. two different Custom Post Types, one per block, e. g. `post_type='products'` and `post_type='projects'`; 2. children of two another pages, e. g. children of "Products" in one block and children of "Projects" in another; 3. pages grouped by some custom field(s); 4. pages sharing two page templates, one for each block. And may be some other methods. It's depends on what site structure you'll have and what type of navigation and some other things you prefer (manual or auto).
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "pages, page template, content" }
Overriding Parent Theme... will cause plugins failure? I overrides the parent theme by copying "header.php" and "footer.php" files to the "child" folder, it is working nicely. But I wonder if I install a plugin that need to edit the "header.php" or "footer.php" files, what will happen then?? Since I override those php files, will the plugin edit the files in "child" folder as well?? Thanks!!
A plugin never edits those files - WordPress uses a system of "hooks" and "filters" that allows plugins to change behaviour without altering code. So, in short, as long as you've created your child theme correctly, plugins will work fine. Some references: * < * <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "plugins, theme development, child theme" }
Questions about MU database schema and how to list all blogs What is the best way of retrieving a list of all blogs and their URLs in a MU network? Can I find them somewhere in the database? I'm also confused about the database schema. I have two different networks, one network has lots and lots and lots of tables with names such as wp_{id}_posts whereas the other network - which is admittedly much simpler - only has one of each kind of table. Notably it also has a table wp_blogs which I cannot find on the first network. Could this be because of the first network was installed way back when the MU feature was new (3.0) and the other network is recent (3.4)?
You can use something like this global $wpdb; $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM wp_blogs ORDER BY blog_id" ) ); Iterate through $blogs to get what you need. There is a function `get_blog_list()`, but it's been deprecated, so you probably shouldn't use it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "multisite, database" }
How do I get the slug of a custom taxonomy category of a post? In my template file, I loop through posts that are categorized either _web_ , _print_ , or _marketing_ in a custom taxonomy _portfolio_. How do I echo the slug of each posts category?
This shouldn't be too hard! $my_terms = get_the_terms( $post->ID, 'portfolio' ); if( $my_terms && !is_wp_error( $my_terms ) ) { foreach( $my_terms as $term ) { echo $term->slug; } }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "posts, categories, custom taxonomy, taxonomy, slug" }
Does doing an export moves all my posts or just a copy of it? I want to move from Wordpress hosting to self-hosting. I have installed wordpress on my self-host account. Now I want to play with it for a while with themes,plugins, etc. and see how it goes. So I am thinking of bringing all my post to my account. I would like my original blog on wordpress to work as usual for now until I am ready to redirect it to my own domain/host. **Question:** So when I use the Export facility (All post) will the posts get permanently removed from my blog or will it be just a copy of my posts?
It's just a copy of your posts.
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "export" }
Show related (archive) month and year to post I want to show the related (archive) month and year for a post next to its contents, i.e. "Archived in January 2012". Any help / directions is greatly appreciated.
Use following code after the loop: $month_num = get_the_date('n'); $month_txt = get_the_date('F'); $year = get_the_date('Y'); // change 'posts_per_page' to any value you need, '-1' means 'all' query_posts( 'posts_per_page=-1&monthnum='.$month_num.'&year='.$year ); echo '<p class="">Archived in '.$month_txt.', '.$year.'</p>'; echo '<ul>'; while ( have_posts() ) : the_post(); echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>'; endwhile; echo '</ul>'; wp_reset_query(); It's not tested, but you got the idea.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, post meta" }
If in category to be inside of a function I have this code in WordPress **index.php** and I was wondering how can I transfer this in to a **functions.php** to be a part of a **function**? <?php if (in_category('featured')) : ?> <a href="<?php the_permalink(); ?>"> <span class="featured_icon"> <img src="<?php bloginfo('template_directory'); ?>/images/featured_icon.png" /> </span></a> <?php endif; ?> Thank You in advance for Your help :)
If you want to use the function to output the code somewhere: function displayImage($currentPost) { // Show the featured icon only if current post is in "featured" category if ( in_category ( 'featured', $currentPost ) ) { $output = '<a href="<?php the_permalink(); ?>"> <span class="featured_icon"> <img src="<?php bloginfo('template_directory'); ?>/images/featured_icon.png" /> </span> </a>'; } else { $output = '' }; return $output; } Then you can just pass the post id and echo the function.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "categories, functions, code" }
Get second level terms of custom taxonomy I want to get second level terms of a specific parent (first-level) term in a custom taxonomy. Sounds complicated but would be useful. Term 1 SubTerm-1.1 SubTerm-1.2 SubTerm-1.2.1 Term 2 SubTerm-2.1 Say, if `SubTerm->parent` is Term 1's id, then i want to output SubTerm 1.1 and 1.2 but not 1.2.1. `wp_list_categories(array('depth' => 2, 'taxonomy' => 'customtax'));` is not i'm looking for as it lists terms with their links, which i dont want to, and there is no filtering option by `SubTerm->parent` id. So any idea?
You can use PHP's `array_filter` to process the results of a taxonomy query function that returns its results, and then display them. Something like: # This returns the whole taxonomy... $whole_tax = get_terms('customtax', array('hide_empty' => 0)); $second_level = array_filter($whole_tax, function ($t) { # This term has a parent, but its parent does not. return $t->parent != 0 && get_term($t->parent, 'customtax')->parent == 0; }); At this point you can render `$second_level` to output in whatever format you want. NB. If this is often used on a busy side should avoid all those extra `get_term` calls by reading from the `$whole_tax` array assuming the documentation's statement that `get_term` always hits the database when passed an id.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 5, "tags": "custom taxonomy, terms" }
Saving Revision of post meta key/value on each update_post_meta event I have some code that updates a meta-key's value by incrementing... $post_id = $wpdb->get_var( $query ); $meta = get_post_meta( $post_id, 'stuff', TRUE ); $meta++; update_post_meta( $post_id, 'stuff', $meta ); I want to create and save a revision of the meta key/ value each time it is updated, so I can determine how many updates took place last week, last month, last year, etc. I am looking at this code here, but I don't want to do it from the edit post screen, it needs to happen when I update the post meta.
You'd need to set up an additional custom field and update it whenever the user changes or updates the original custom field.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "date, post meta, revisions" }
How to set order for attachment form field? I'm adding some fields to attachment edit form by add filter to "attachment_fields_to_edit". The added fields work fine but they are not rendered as the order I added them. Is there a way to order the fields?
Yes there is. Add css styles for the form or more precisely try to add names in class attribute of the fields. This should help to properly render the order. For this you may want to check the class names of existing fields which was rendered correctly.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "attachments, attachment fields to edit" }
Way of getting queried loop before the query with a filter hook? Is there a way to get the results of a loop with a filter before the code for the loop is performed in the structure of your code? My markup is something like this: <body> <div> /* can I use a function to get the results from a loop performed after this point with a filter or hook of some sort */ </div> <div> /* a loop/foreach etc. with results I would also like information for above */ </div> </body> or would I need to duplicate the loop/foreach or restructure the page to achieve this?
@Rutwick's answer was what I thought when I read the title, but I think you're just wanting to use `get_the_terms()` which can be out of the loop like this: $my_post_terms = get_the_terms( $post->ID, 'show' ); if( $my_post_terms && !is_wp_error( $my_post_terms ) ) { // do something here with $my_post_terms array }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, loop, filters, php" }