INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
wp_get_attachment_image_src() with advanced custom fields returning empty I am using the advanced custom fields plugin to upload images for an image gallery. I am attempting to retrieve the different sizes of images that are saved in the uploads folder and having problems. $image = wp_get_attachment_image_src(get_sub_field('image'), 'full'); When I echo out the results of this I get nothing. I know that the images are being saved as different sizes because I can see them in the uploads folder and the get_sub_field('image') is returning the proper image src. Is there anything else I need to do to get this to work?
What's in get_sub_field('image')? wp_get_attachment_image_src() parameter 1 should be the attachment id, not the attachment src, if that's what you have. I use the following function to get an attachment ID from an image url as as far as I know WP doesn't have a method for this at present. function get_attachment_id_from_src ($src) { global $wpdb; $reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i"; $src1 = preg_replace($reg,'',$src); if($src1 != $src){ $ext = pathinfo($src, PATHINFO_EXTENSION); $src = $src1 . '.' .$ext; } $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'"; $id = $wpdb->get_var($query); return $id; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, images, thumbnails" }
A plugin, which allows editing certain template regions > **Possible Duplicate:** > What methods to use to create small, editable pieces of text for static pages? I'm looking for a plugin, which would allow editing of certain predefined template regions. For example: I define that footer text is editable and administrator is able to edit just that, without touching code in template editor.
Wyck pointed me to this answer: What methods to use to create small, editable pieces of text for static pages?. And WP-Blocks was exactly what I needed after a few compatibility fixes :)
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Not showing list if there aren't any categories to display maybe you can help: Bellow there is a simple code listing my blogs categories. **I need some code that will not display the * _ul** is there aren't any categories to display_* <ul> <li><p>Categories:</p></li> <? $master_cat = get_category_by_slug('Master'); $master_cat_id = $master_cat->term_id; $slave_cat = get_category_by_slug('Slave'); $slave_cat_id = $slave_cat->term_id; wp_list_categories('orderby=name&title_li=&exclude='.$master_cat_id.','.$slave_cat_id.''); ?> </ul> Ty very much
<?php $master_cat = get_category_by_slug( 'Master' ); $master_cat_id = $master_cat->term_id; $slave_cat = get_category_by_slug( 'Slave' ); $slave_cat_id = $slave_cat->term_id; $categories = wp_list_categories( 'echo=0&show_option_none=&orderby=name&title_li=&exclude='.$master_cat_id.','.$slave_cat_id ); if ( $categories ) : ?> <ul> <li><p>Categories:</p></li> <?php echo $categories ?> </ul> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories" }
How do I implement a .diff changeset from core.trac.wordpress.org locally? I have a local copy of the latest version of wordpress that I set up using svn co There is a diff that I want to pull into my local fileset: < Is this something that I can do with subversion? What commands do I need to use?
The command you need is `patch` which is not specific to SVN. It's really easy to do. See this article: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, core, customization, svn, version control" }
How to have a category not show up in query post with page panigation? Basically I have this loop that shows all post. Inside of it I want to exclude post's from categories including shirts and hoodies, also the gallery category. Here is what I have so far. the code works without the 'cat=-gallery". But with it, it does not show any post's at all. <?php $limit = 5; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( 'cat=-gallery&showposts=' . $limit . '&paged=' . $paged ); $wp_query->is_category = true; $wp_query->is_home = false; ?> <-----my blog stuff----> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php next_posts_link('Older Entries »', 0); ?>
When using cat in the query you need to specify the category id not name. Try this. <?php $gallery = get_cat_id('gallery'); $shirts = get_cat_id('shirts'); $hoodies = get_cat_id('hoodies'); $excluded_cats = '-'.$gallery.',-'.$shirts.',-'.$hoodies; $limit = 5; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts( 'cat='.$excluded_cats.'&showposts=' . $limit . '&paged=' . $paged ); ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, query posts, exclude" }
Permalinks without subdirectories Today I use: permalink_structure: /%postname% This gives me URL like this on my pages: 1. # 2. # 3. # But I want it to be: 1. # 2. # 3. # How can I make this happen? I still want to use the parent function in wordpress admin... **The reasons why I want this are:** * It looks so much better * When I (or some one else) change URL of page1 I am not messing up the URL for page 2 and page3 (less 301 work) * (Better SEO)
One solution would be to create all your pages as root pages and then use the Menu page in "Appearance -> Menus" to define the structure of the pages. This assumes that your theme supports Menus, which the default Wordpress themes TwentTen and TwentyEleven do. **Update:** Here's a couple of links that might help you do this without using the menus functionality (as I fully agree with your comment that it's a little annoying to use the menus functionality). This is a plugin which seems like it might help: < And here's an example of hacking the Wordpress core code (which I would generally not recommend): < I haven't tried either though.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks" }
Updating seperate database when post attachment is changed I have a seperate database with lists of users, brochures and brochure URL's, and timestamps of when a brochure was ordered, but I want my database to update everytime a brochure (PDF) attachment is updated in the admin back end of wordpress. When a user requests a brochure they receive a reminder after a few days wiuth a link to the PDF they requested. I have most of it figured out I just need to know how this link can constantly link to the latest PDF of the brochure they requested. Thanks :)
You can hook into `add_attachment` and/or `edit_attachment` actions and carry out an update on your separate database with the appropriate info. In both cases the attachment ID seems to be the only argument but you can easily `get_post` or `get_post_meta` if you need anything else. Cheers!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "database, updates, pdf" }
Why do we include jQuery in the header? I was told not to mess with the core files. Also, I don't want jQuery to load on every single page.
Get rid of the plugin/theme that's causing jQuery to load :) jQuery is shipped with WordPress doesn't mean that it's loaded every time by default, it's being loaded by a theme or plugin that you're using. Look for a call to `wp_enqueue_script` :) Good luck!
stackexchange-wordpress
{ "answer_score": 6, "question_score": 3, "tags": "jquery" }
Need help changing back the correct wordpress url Hello I've just recently installed wordpress today on a development linux server. Everything seemed ok until when I stupidly changed the wordpress url. Initailly it was just < but I changed that to < in the settings area. Now I cannot seem to login again, because everytime I login, it takes me to a page 404 error. So is there another way to change the wordpress url?
Did you follow the steps outlined here: < Specifically did you copy the .htaccess and index.php files back to the root and edit the index.php file with correct filepaths as stated in points 7 - 9? **Update** The problem was solved by modifying these two options in the wp_options table: * `siteurl` * `home` (See comments)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "urls, localhost, linux" }
Set or change default text in hyperlink popup in post editor When writing a post or page in the post editor (not the Visual editor but the HTML editor) and clicking on the "link" button, a popup appears with ` already prefilled. Is there a way to change this default text? For example, since I usually link internally to my own site I would want to use my base URL because then I could either quickly type the rest of the URL, or just overwrite it if I was hyperlinking somewhere else. ` I swear I saw a blog article on how to do this but I cannot locate it through searching the web. Thanks in advance for any help.
You could try hacking into wp-includes/js/tinymce/plugins/wplink/js/wplink.js and change: * `if(!i.href||i.href==" (two times) * `b.url.val("
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "html editor" }
"Automatically add new top-level pages" Default I'm looking for a way to set the default "Automatically add new top-level pages" to be checked when creating a new menu. I haven't been able to find anything on this - any help you could give me? Thanks!
<?php add_action( 'wp_create_nav_menu', 'PREFIX_nav_menu_auto_add_by_default' ); function PREFIX_nav_menu_auto_add_by_default( $id ) { $options = (array) get_option( 'nav_menu_options' ); if ( ! isset( $options['auto_add'] ) ) { $options['auto_add'] = array(); } $options['auto_add'][] = $id; update_option( 'nav_menu_options', $options ); }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "admin, menus" }
Wordpress multisite,one theme,and different languages? I'm not sure is this possible,for example I have english,french and italian blog,they all use same theme,I just want when visitor is on french site for example to display date,(some strings like search,next page,...) on French,can I do it with theme localization an how,how to setup wordpress multisite to use this theme localization?
See < Basically after you install the language packs, go to that site and change the language option from the admin area.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "multisite, localization" }
Wordpress will not operate correctly My website is ImASpy.com. If you click on the link, Findings, this takes you to my first Wordpress page. It appears to work fine until you click on comments, or you try to go to the about page, which is another Wordpress page. it stops working and usually gives a database error. Even worse, I cannot get into my Wordpress administration. Any idea what's going on? If you need details please let me know what you need. I can give you the entire Sql file or the wp-config.php if you need it. Thanks!
You probably messed up with the config on the DB I would like the dump of the config table please, that way i can see the paths to your wp install (i had a similar problem which i solved by manually correcting the fields in DB) **EDIT** Run this sql query and let me know : UPDATE `wp_options` SET `option_value` = ' WHERE `option_name` = 'siteurl' OR `option_name` = 'home'
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "php, mysql, database" }
Changing WordPress sort order for returned child pages I have a custom `WP_Query` that looks like this: $this_page_id=$wp_query->post->ID; $images = new WP_Query( array( 'post_type' => 'menu-item', 'post_parent' => $this_page_id ) ); My problem is that when using the `orderby` parameter (see here: < to sort by `menu_order` (which I need to do for the project). The sort order is not working. I'm 99% certain the reason it's not working is because I'm directing it to query all children of a specific post and the `orderby` parameter doesn't "dig that deep into the query" if that makes sense to anyone. Can anyone offer some help? doing this (the expected solution yields nothing): $this_page_id=$wp_query->post->ID; $images = new WP_Query( array( 'post_type' => 'menu-item', 'post_parent' => $this_page_id, 'orderby' => 'menu_order' ) );
This query should work. $images = new WP_Query( array( 'post_type' => 'menu-item', 'post_parent' => $this_page_id, 'orderby' => 'menu_order', 'order' => 'ASC' ) );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, query, loop, order" }
Menu items do not "open" when mouse hover over them? I am using "basic magazine" wootheme, and for some reason my top menu navigation bar doesn't "open" when I hover the mouse above it: < Is there some CSS problem there? How can I detect/fix the problem? Thank you.
Seems like the superfish menu plugin is not setting the CSS properties correctly when hovering over the menu item. You can fix this by updating the CSS in your styles.css file at line 155 from: .nav2 li.sfHover ul, ul.nav2 li:hover ul { background: none repeat scroll 0 0 #B3B3B3; color: #FFFFFF; text-decoration: none; z-index: 1000; } to: .nav2 li.sfHover ul, ul.nav2 li:hover ul { background: none repeat scroll 0 0 #B3B3B3; color: #FFFFFF; text-decoration: none; z-index: 1000; visibility: visible!important; display: block!important; } This overrides the visibility and display settings that are being set inline on the element itself by superfish.js, but are not being cleared when you hover over the menu item.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes, css" }
Firebug : Problem with jQuery in WordPress admin panel I'm trying to make my first plugin and I have a problem with firebug. When I use firebug console in WP Admin Panel doesn´t work correctly. For example when I use the selector $('#wpbody') the console return null value. The WP panel include jQuery library and I don´t know why firebug works wrong. Any advice or sugestion? Tested with WP 3.1.3 and 3.2.1 Thanks, Marcos.
WordPress uses jQuery in `noConflict()` mode, so `$` is not available for use in Firebug console. Just use `jQuery('#wpbody')` instead.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "jquery, admin menu" }
Getting the Posts' permalinks from XLMRPC I'm new to WP and I must fetch pages/posts from a blog in another subdomain. I'm using ZF to do this. I've recently found out the `getPages` doesn't get me what I want (posts; duh!). I didn't see any "getPosts" rpc methods for WP, so I've tried `blogger.getRecentPosts`. That's better, but now I don't have the permalinks. It would've been nice for it to return the same values as `getPages` does (title, permalink etc.). I'm considering modifying (through filters, ofc) the WP's RPC server to return pages and all the relevant information, but, for now.. Is there a RPC method for WP to get Posts and their permalinks?
Use the metaWeblog api instead: "metaWeblog.getRecentPosts". This includes the permalink information. See here: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks, get posts, xml rpc" }
Can't seem to see images on my machine but can on the server Hello I just started using wordpress (complete noob) but I need a bit of help. I have installed wordpress and on a linux/centos webserver and this works fine. However when I use another machine, open a web browser, type in the url, the site looks different from what it looks like on my server. (On my web server, there is a choice to use the Graphical user interface as well) The difference is the images don't appear on my machine (Looks like it can't find the media files). Also when I click on any link (the 'Hello world', login etc.), it says Firefox can't establish a connection to the server at localhost. I can see the images on the webserver and all links are fine. So I don't now what the problem Just to let you know my wordpress url is localhost and my site url is also localhost if that may help.
"localhost" normally points to the webserver on the machine the request is made from. You installed wordpress on your server to run under "localhost". So if you open a browser whilst on the server and go to "localhost" it will look for the site on the server and find it. However, if you open a browser on your "dev machine" and go to "localhost" it will look for the site on your dev machine and it won't find it there as you installed it on the server. Now, if you're connecting to the site using your server domain name (eg < then whilst that request will work, the links to the images and other posts will not work because Wordpress creates those links as " which your browser will look for on your local machine and not find there. The best solution: Logon to the site from a browser on your server and change the URLs in the dashboard to your server's domain name and always use that domain name to connect to the site.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images, media, localhost, deployment" }
Error when updating plugins by FTP "Unable to locate WordPress Content directory (wp-content)." I run apache2 on Ubuntu, i'm sure there is a configuration or permission problem causing this. When I attempt to update plugins through the admin control panel, after I enter the FTP login/pass and click Proceed. I get the error "Unable to locate WordPress Content directory (wp-content)." And wp-content does exist and have proper permissions from the default install.
I ended up using code from this post on WordPress.org Place this into my wp-config.php file if(is_admin()) { add_filter('filesystem_method', create_function('$a', 'return "direct";' )); define( 'FS_CHMOD_DIR', 0751 ); }
stackexchange-wordpress
{ "answer_score": 6, "question_score": 6, "tags": "plugins, updates" }
Make jQuery library load before plugin files I am using a few jQuery plugins such as validate.js, but they all load BEFORE the Jquery library which is loaded automatically by WordPress and my theme. I need the plugins to load after - so is there a way to make Jquery load first in functions.php - so that I can use it frontend and admin. I am currently loading the following in functions.php wp_enqueue_script('validation', get_bloginfo('template_url') ."/js/jquery.validate.min.js"); wp_enqueue_script('scripts', get_bloginfo('template_url') ."/js/scripts.js"); Any help, massively appreciated!
If you look at the `wp_enqueue_script` Codex Documentation, you'll see one of the options is `$deps`, this would mean that your script is dependent upon another script, simply add **jquery** as a dependancy and your scripts will load in the correct place. If you set a handle for the other scripts you can use them as a dependent as well. Example: wp_enqueue_script( 'your-handle', get_bloginfo('template_url') . '/path/script.js', array( 'jquery' ) );
stackexchange-wordpress
{ "answer_score": 10, "question_score": 6, "tags": "jquery, wp enqueue script" }
How to properly secure my Wordpress installation? I'm currently on my own server (fredericpilon.com) with my own website. Wordpress being kind of a big shot of CMS, it may be targeted by hacks. Any tips and tricks on how to properly secure my Wordpress installation from said hackers and evil-doers?
Links: * < * < (lots of great articles) * <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "plugins, security, server, installation" }
Moving wordpress to an unknown outlet I have some wordpress websites on one server that I want to download. The problem is I don't know what url or what server I am moving it to. The problem is I do want the original to work. Suggestions on what I should do? This Wordpress Codex suggests I already know where I am moving the wordpress... Suggestions on what I should do?
I wouldn't worry too much about it - just download all databases and files. And if you're uploading them to the new server, change the wp-config files and run the following queries on the databases: UPDATE wp_options SET option_value = replace(option_value, ' ' WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, ' UPDATE wp_posts SET post_content = replace(post_content, ' ' If your permalinks are still not working, delete the .htaccess file, and go to Settings->Permalinks and click save to create the .htaccess file.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "server, migration" }
How can I see all the actions attached to an "add_action" hook? I'm working with the admin bar and trying to debug some of the menus and their priorities. I know several callbacks get bound to actions, such as this one: add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 ); How can I see what is lined up to be called when a hook like `admin_bar_menu` is called?
You can see the detailed list of the hook using this snippet: $hook_name = 'admin_bar_menu'; global $wp_filter; var_dump( $wp_filter[$hook_name] );
stackexchange-wordpress
{ "answer_score": 36, "question_score": 21, "tags": "plugins, php, hooks, actions, debug" }
Need help sorting "My Sites" Alphabetically I have 40+ sites showing up in the "My Sites" page with more planned. Unfortunately WordPress doesn't sort them alphabetically, and that makes it a pain to move from site to site during routine updates and maintenance. I've tried adding asort($blogs); to wp-admin/my-sites.php, but that doesn't help either. And regardless, I'd rather do this using a filter in functions.php rather than modifying a core file. Making the issue even more complex is the fact that the list is split into four columns, and while a horizontal alphabetical ordering would be a huge improvement, vertical (by column) would be much, much better. I've been searching for answers for this for a while and coming up empty, so any help would be appreciated. (My PHP is pretty basic, so spelling out the answer would definitely be appreciated.)
Easy one. <?php /* Plugin Name: Sort My-Sites Description: Sorts the My Sites listing on both the page and in the 3.3 admin bar dropdown Author: Otto */ add_filter('get_blogs_of_user','sort_my_sites'); function sort_my_sites($blogs) { $f = create_function('$a,$b','return strcasecmp($a->blogname,$b->blogname);'); uasort($blogs, $f); return $blogs; } Edit: If you want a PHP 7 version: add_filter('get_blogs_of_user', function( $blogs ) { uasort( $blogs, function( $a, $b ) { return strcasecmp( $a->blogname, $b->blogname ); }); return $blogs; });
stackexchange-wordpress
{ "answer_score": 13, "question_score": 10, "tags": "multisite" }
How do I disable trackback notifications on a WordPress.com blog? I tried < but it didn't work. I do want unregistered users to be able to comment. == What I dont want is email notifications like this: > New trackback on your post "we also analyzed zonal wind too" Website: Quora (IP: 107.20.3.229 , ec2-107-20-3-229.compute-1.amazonaws.com) URL : < Excerpt: **How can faster rotation rate lead to an increased pole-to-equator temperature gradient when the zonal velocity of the jet stream decreases, as predicted by both the Held-Hou model of circulation and one of the CAM3 simulations that I ran?...** > > Supposedly, faster rotation rate means a stronger Coriolis effect, which means that a tropical parcel of air that goes poleward in the meridional direction is more likely to be deflected in the zonal direction. Yet, the Held-Hou model of circulation pr... > > You can see all trackbacks on this post here:
Go to your site's dashboard. Then navigate to Settings » Discussion and disable the "Allow link notifications from other blogs (pingbacks and trackbacks)" option: !Trackback Option
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "wordpress.com hosting" }
Blog automatically redirected to error page I have a blog link. It was loading fine, but now when I open it. It redirects to error page.
there's a meta tag in your body, causing refresh: <meta http-equiv="REFRESH" content="0;url=error.htm">
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "errors, 404 error, blog" }
If statement for catergories I was wondering if someone could explain how to roughly code this into php: if catergory = Cars && user is unregistered <my code> else <my code>
<?php $current_user = wp_get_current_user(); if ( is_category( 'Cars' ) && 0 == $current_user->ID ) { ?> <!-- HTML markup here --> <?php } else { ?> <!-- other HTML markup here --> <?php } ?> ID will be 0 in the `$current_user` object, if the user isn't logged in. Related reading: * `is_category` * `wp_get_current_user` **EDIT** Try using `is_user_logged_in()` and `in_category()` instead: <?php if ( in_category( 'cars' ) && ! is_user_logged_in() ) { // Current post is in the category 'cars' // and the current user is NOT logged in; // do something } else { // do something else } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories" }
Linking to Post Types from wp-admin Morning all, I'm having a bit of trouble finding a function I can use to link to a post type from the admin area. I'm actually using something as simple as: `<a href='edit.php?post_type=slides'>Slides</a>` in another area, but didn't know if there was a better way of handling it (since I'm still technically hardcoding in the first part of the URL). The post type name being hardcoded isn't the issue, really just generating that first part of the URL. Thanks!
The following should do the trick: <a href=" <?php admin_url('edit.php?post_type=slides') ?>">Slides</a> It's how it's done in the source code. The function `admin_url()` appends the proper admin address. The output of the url should be:
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom post types, admin, links" }
Wordpress members-only page with link visible only to members How to achieve Wordpress members-only page functionality with a link in the primary menu visible only to members? Is there a plug-in for that? The Wordpress version is 3.2.1. It is self hosted.
< seems to do what you need. You can probably also use < but it's sort of complicated.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "user registration" }
Registration options and approvals What are the possible registration options in Wordpress (everybody can register, nobody can register, only some users can register)? More specifically: * can Wordpress be setup so that only those users that are previously approved are registered? * can registrations by users be prevented altogether so that all registrations are done by the administrator? * can all readers who wish so be registered?
The "Settings > General" Screen has a checkbox for "anyone can register." This answers your second and third questions - it depends on how that setting is set. For your first question, that functionality is not built into WordPress. Perhaps a plugin like WP User Registration would suit your needs for this bit of functionality. Good luck!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "user registration" }
Wordpress multisite,use same cookies across all website? Hi is this posible to use same custom cookies across all blogs?Can someone help me with this?
Came across this support topic which may be helpful. It indicates the following for your `wp-config.php` file: define('ADMIN_COOKIE_PATH', '/'); define('COOKIE_DOMAIN', ''); define('COOKIEPATH', ''); define('SITECOOKIEPATH', '');
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugin development, multisite, functions" }
Shortcode does not expand in Facebook like I am using Facebook Like Button plugin on pages that just contains a shortcode. When I Like the page and post to Facebook, it shows the shortcode without expanding it. I want to show the expanded contents in Facebook activity stream
If I understand the question correctly, it sounds like the content is being sent without using do_shortcode(), find the portion of the plugin that posts to facebook for you and ensure shortcodes are being executed.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, facebook, shortcode" }
How to remove index.php from a tag or archive page URL in the root blog? I'm developing a Multisite where the root site is an agregator (using the mu-sitewide-tags plugin). I created a custom widget to show tags across all sites, but when I click on the tag page on the main blog, it loads like this: < I tried to remove it creating a custom permalink, but wordpress doesn't allow to take it off. Is that possible to do it? Any idea?
try to flush your permalink structure that might be the issue
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "multisite, permalinks" }
Tumblr-like Post Types for WordPress Is there any way to get Tumblr-like post types for WordPress? Ones where when you select a post type, it gives you different fields in the post editor for that type. For instance, if there was a link post type, I could enter the URL, the title, and an optional description of the link. Or, for a photo, I could enter a title, browse for the photo, and enter an optional description.
Alex King made a plugin that creates a different admin UI for each Post Format type. More info here: <
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "posts, post formats, tumblr" }
shortcode inside another shortcode I wonder if is it possible to have a shortcode inside another one? My scenario is this: I create a shortcodes to display content into columns so I can manage the layout of the page more easily. Now the problem comes, when I try to use for sample nextgen gallery into one of those shortcodes. For some reason it just generates the shortcode as plain text. Any idea why? I will show you the code I'm using for the shortcode maybe it helps: // Column ShortCode Description function column_scdescription($atts, $content="null") { return '<div class="description">' .$content . '</div> <!-- description ends here -->'; } add_shortcode ("product-description", "column_scdescription"); Thanks in advance.
I usually apply the_content filters to $content to do this. I think you can aslo use do_shortcode($content); // Column ShortCode Description function column_scdescription($atts, $content="null") { return '<div class="description">' .apply_filters('the_content', $content) . '</div> <!-- description ends here -->'; } add_shortcode ("product-description", "column_scdescription"); Read up on Nested Shortcodes in the codex.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 3, "tags": "shortcode" }
Using add_sub_menu to put into Appearance Section I am working on a new plugin, and want to add my plugin menu to the Themes/Appearances section. add_submenu_page('themes.php','Widget Area Manager','administrator','widget_area_manager','wm_area_manager_admin'); However the menu get's added to the setting's section of the dashboard. What am I doing wrong?
Try this code. function widget_area_mamanger(){ add_theme_page( 'Widget Area Manager', 'Widget Area Manager', 'administrator', 'widget_area_manager', 'wm_area_manager_admin' ); } add_action('admin_menu', 'widget_area_mamanger');
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugin development" }
Access denied error when logged in as admin What are the possible causes for getting the "You do not have sufficient permissions to access this page." message when logged in as admin? I've done a lot of searching and found a lot of possible solutions, but in my case they haven't worked. In my case I've taken a copy of a database off our staging site (close enough to having the same code) and placed it on dev, done the usual steps of changing values in the options table, gone to the lengths of disabling all plugins (through the database, even to the point of renaming the plugins folder). It was a multisite install at one stage (but this should have been cleaned up). I can log in, but get the access denied when I try and go to the dashboard page.
In my case it happend that the capability for user 1 somehow got wiped, so the SQL command: INSERT INTO wp_usermeta (user_id, meta_key, meta_value) VALUES(1,"wp_capabilities",'a:1:{s:13:"administrator";b:1;}'); did the trick.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "user access" }
How to get template drop down menu in page-attributes of custom post type? When I register my custom post type, I set this: 'hierarchical' => true, 'supports' => array( 'title','author', 'page-attributes' ), So, I am supose to see 'order', 'templates', 'parents' in Attributes box when create new post. But, I don't see the 'templates' drop down showing up. Anything else I should do to enable the choice of 'templates' ?
You can't apply templates to custom post types in this manner. That will show up only if the post type is 'page' ( Check the wp-admin/includes/meta-boxes.php line 568 ). However if you want to style all your single custom post types in the same manner but different from other post types you could use the single-[posttype].php -> <
stackexchange-wordpress
{ "answer_score": 6, "question_score": 10, "tags": "custom post types" }
Echo author ID in author.php This is probably a super simple question. But how do I echo the ID of a user on author.php? I've tried the_author_meta('ID') But it didn't seem to want to work. I want to echo it at the end of a URL, for example; < Obviously, where "id" is that particular author's ID Any ideas?
Try this code. $author = get_user_by( 'slug', get_query_var( 'author_name' ) ); echo $author->ID; Alternatively, if author name has not been set use: if ( $author_id = get_query_var( 'author' ) ) { $author = get_user_by( 'id', $author_id ); } _credit @AndyAdams in the easily missed comments bellow_
stackexchange-wordpress
{ "answer_score": 31, "question_score": 13, "tags": "author, template tags, id" }
wp_nav_menu not appearing for a couple pages _I solved the problem with the page, the correct answer is ptriek's comment below._ Well I'm having a bit of an odd problem here, wp_nav_menu works on all pages EXCEPT my category pages (probably my archive page too but there's no links on the website to the archive pages so that's alright). Although there is archive.php in my theme files, this controls what is displayed on category, tag, archive, author, etc. pages. I just don't understand why, since every page uses the same header.php to display wp_nav_menu, it won't show up for the category pages. Am I overlooking something? I've been banging my head against my keyboard trying to figure this out and it just won't work! Using a very simple code: `<?php wp_nav_menu('container_class=menu-header&theme_location=primary'); ?>`
I had the same problem, but with a newer version of Wordpress (3.7.1). On pages with custom taxonomies of custom posts, the wp_nav_menu was not shown. The solution below worked for me. in functions.php of the theme: add_action( 'pre_get_posts', 'my_pre_get_posts' ); function my_pre_get_posts($query) { if ($query->get('post_type') === 'nav_menu_item') { $query->set('tax_query',''); } }
stackexchange-wordpress
{ "answer_score": 6, "question_score": 4, "tags": "categories, theme development, navigation" }
Change post_date to post_modified date on post template? I'm looking to change the post created date to a modified date on my post template (single.php). Moreso, I'm looking to control when I update that date based on whether I make significant changes to the post. I'm thinking I might have to create a custom field as well as an option box in the edit post screen to set the custom field. Maybe there's a simpler way?
use this into the loop or if you want to change created date to modified date than replace that with below code. As I know this feature works from all version of wordpress after 2.1 <?php the_modified_date(); ?> More detail you can find here <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "posts, templates, post meta" }
if not empty bloginfo('description') Can someone tell, how to check whether it's empty? <?php bloginfo('description'); ?> Something like: <?php if (!empty bloginfo('description');) ?> Thanks a lot.
if ( get_bloginfo( 'description' ) ) { //do something } bloginfo echoes the description, get_bloginfo returns php variable
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "bloginfo" }
orderby ignored by wp_query With the following code, I do not get the result set ordered by titles. No matter what values I give to 'orderby' and 'order', I get the same ordering. The parameters seem to be ignored (or overridden?) by something else.. Any idea how I troubleshoot this one? Is there a specific filter I should be looking at, that some plugin could be overriding this via? Should the code below work out of the box? IF it looks correct, something must be interfering. $args = Array( 'post_type' => 'post' 'category_name' => 'reviews' 'posts_per_page' => '999' 'orderby' => 'title' 'order"' => 'ASC' 'post_status' => 'publish' ) $customloop = new WP_Query(); $customloop->query($args); while ($customloop->have_posts()) { ... }
I noticed you have an extra quote after order in your args. That affecting it?
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp query, order, sort" }
What is the best way to detect IE browsers 8 and below? I'm using some HTML5 functionality that only works on IE9 and I need to detect whether visitors are running on IE8 or below (mainly just IE8 or 7 of course). I've tried some plugins but the one that was working didn't seem to support IE9 (just up to 8). It's called PHP Browser Detection (
I would suggest using that plugin, but slightly modifying it for your needs. For example, you can find the code block in php-browser-detection.php that does the IE7 check: function is_IE7 (){ $browserInfo = php_browser_info(); if(isset($browserInfo['browser']) && $browserInfo['browser']=='IE' && $browserInfo['majorver'] == '7') return true; return false; } To create a version that will detect IE 8, add a new function that does the same thing, but just with the majorver set to 8: function is_IE8 (){ $browserInfo = php_browser_info(); if(isset($browserInfo['browser']) && $browserInfo['browser']=='IE' && $browserInfo['majorver'] == '8') return true; return false; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "browser compatibility" }
How to make an archive page template using Wordpress 3 I have a suitable page, archives.php, located in the theme's root directory, but I cannot get it to show up as a page template. Is there something else I need to do so that it is recognized?
Archives.php is usually not a page template - it is a file used to display all the archived posts (usually some sort of list ...) It is usually triggered by a function that deals with archived posts like <?php wp_get_archives('type=monthly'); ?> Anyhow - A page template file has to have this code in the begining ; <?php /* Template Name: put name here */ ?> in order to show as page template .. so should you really want to make archives.php to work as a template file - /* Template Name: Archives */ should work.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "archives, page template" }
Remove unwanted part of permalink custom structure from CPT url? My site currently has regular posts (in a section called "Trend Watch"), as well as a Custom Taxonomy (called "Region"). My permalink settings have this Custom Structure: /trend-watch/%year%/%monthnum%/%postname%/ which gives me these urls: * `/trend-watch/regions/` (lists all terms in the Regions taxonomy) * `/trend-watch/regions/europe/` (lists all posts with the term "europe" in the Regions taxonmy). * `/trend-watch/2011/03/an-interesting-article/` (a single post). But now i'm adding a new Custom Post Type, called Reports. When registering this CPT, I set `rewrite => array('slug' => 'reports')`. But the urls are including "trend-watch/" first: /trend-watch/reports/some-report/ How can I remove "trend-watch/" from the Reports CPT urls, but keep it for regular Posts (and the associated Custom Taxonomies).
You need to set the 'with_front' parameter in the rewrite argument for the custom post type to false. 'rewrite' => array('slug' => 'reports', 'with_front' => false)
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "custom post types, permalinks, url rewriting" }
Link Posts to External URL I'm building a site which lets users to submit links using User Submitted Posts plugin. I want every post title to link to its URL something like reddit. Moreover, User Submitted Posts plugin add URL to each post in the posts meta table. How could I do that?
I just released a plugin that does pretty much that... you may want to take a look at the Recommended Links plugin and see how its done... or if this plugin works, try converting your links to the custom type I'm using and just install this plugin. My approach was to create a new custom post type for these links, add a postmeta entry for the URL they should link to, and filter `the_permalink` to refer to the link from postmeta, rather than the permalink for the post. I also created a basic widget to allow users to submit their links, and filtered `the_content` and `comment_text` to add voting buttons to each submitted link and comment on it.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, posts, customization, post meta" }
Gel all image from certain post type I've found similar questions here, however I can't modify the answers to get images only from a certain post type - as the post type in those examples are "attachment" and not the name of a custom post type. Is there a way to declare a custom post type argument as well? Similar question, another similar question
Try this code in your template. $query = new WP_Query( array( 'post_type' => 'custom-post', 'posts_per_page' => -1 ) ); if( $query->have_posts() ){ while($query->have_posts()){ $query->the_post(); $image_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'image', 'posts_per_page' => -1, 'post_parent' => get_the_ID() ) ); while( $image_query->have_posts() ) { $image_query->the_post(); echo wp_get_attachment_image( get_the_ID() ); } } } Replace `custom-post` with you custom post type.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "attachments, gallery, media library, post type" }
Store in media library image uploaded from url Is there a plugin that when upload from url/web, it will also give an option to store the images locally and/or into the media library?
I am afraid the upload through url does not uploads the image on your site server but it just inserts it in to the post so it can not appear in the media library. ## Through a plugin You can use the Grab and save plugin to achieve what you want but i think you don't need a plugin for this read the instruction below and you will understand why? ## Without a plugin needed However you can upload the image through a url and then insert it in the post so that it will also appear in your wordpress media library **without the use of any plugin** to do so follow the following instructions. 1. Click add image button 2. In the upload from computer tab click on `select file` button 3. In the `file name` field enter the `url` of the image and click open !Reference image the image will be upload from the site and will now also appear in the media library
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "images" }
disable defaault wordpress comments from a plugin I am modifying the facebook comments plugin to my purposes. What I'd like to do is have it remove Wordpress native comments automatically if it is enabled- in fact what I'd really like it to do is use the Wordpress comments settings in the item itself and/or general settings to decide whether it should show or not. Disqus works like this and its just how you would expect a comments replacement system to work by default- I think this plugin should work like that unless you tell it to do otherwise. Does anyone have any ideas how disqus achieves this? D
Most themes used `comments_template` to include their comment areas. It's completely full of filters, one of which is the include file (usually comments.php) that you can hijack to include a file from your plugin that contains all the stuff for facebook comments (or nothing if you just want to disable comments. Example: <?php add_filter( 'comments_template', 'wpse35363_comments_template' ); function wpse35363_comments_template( $file ) { return plugin_dir_url( __FILE__ ) . 'path/to/your/file.php'; } As far as general settings and per post settings, those are stored in `wp_options` and `wp_postmeta` respectively. Take a look at how the default comments compat file looks and you should get an idea about how you can do this in your plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin development, comments, facebook, disqus" }
I've got a function that auto creates taxonomy terms - Can it auto delete them as well? I've got this inside my functions.php file. function add_product_category_automatically($post_ID) { global $wpdb; if(!has_term('','product_relation',$post_ID)){ $cat = get_the_title($post_ID); wp_set_object_terms($post_ID, $cat, 'product_relation'); } } add_action('publish_product', 'add_product_category_automatically'); It creates terms in the 'product_relation' taxonomy when a product is published. Is it possible to also have the terms automatically deleted when the product is moved to the trash? Thanks
There was some confusion in the original question with the terminology i used. I didn't find a way to do what i was after but it's to late for me to do it now.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom taxonomy, functions" }
CPT Metabox with email notification I have a custom post type just for contacts, I want to create a metabox with the contacts birthday and have it notify the site admin when it comes up (Or a day/week/month before the date if possible).
WP doesn't have a _real_ Cron Job System/APi, but it got the _Schedule API_ , as you can see here. Other related functions can be found here in codex filed under " _See Also_ ". That's the closest you will get with WP.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, metabox, email" }
The effect of spam comments on hosting resource usage (CPU) One of my WP sites is using a lot of CPU, and I am wondering if this is caused because of the high number of spam comments it is getting. Can that be the case? Is there an easy way of checking that? Thank you.
Any time your traffic goes up your CPU usage will go up. Based on what you're saying it could be bot activity. I'm also assuming you're on a shared host that is overloading the server with 10 billion accounts. My suggestions include: * Running a virus scan for WordPress via any number of available plugins * Minimize the number of plugins you're running, as they can impact your CPU usage * Decrease your database size, be sure deleted tables are actually deleted * Add a cache plugin < * Look for unusual/frequent bot activity and block those suckers
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "performance" }
wpdb->get_var - count author posts, meta value In an author.php template, i count the author post in a custom post type with $wpdb->get_var, $post_author = $curauth->ID; //author id $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = $post_author AND post_type IN ('ideas') and post_status = 'publish'" ); is it possible to count the author, total votes saved in post meta with key 'votes'? the value for every post is a number updated each time a user votes a post thanks!
This wouldn't be possible unless you keep a log of users that have voted the Idea. You will have to create another hidden post_meta array which will store a list of all the users who have voted the Idea. In that way you could count the number of votes an author has given. Or better yet you could create and update the **user_meta** 'ideas_voted' when a particular idea is voted by a user. if ( idea is voted ) { $ideas_voted = ( get_user_meta( $curauth->ID, 'ideas_voted' ) ) ? get_user_meta( $curauth->ID, 'ideas_voted' ) + 1 : 1; update_user_meta( $curauth->ID, 'ideas_voted', $ideas_voted ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post meta, author, wpdb, count" }
Image.php Problem - Post Images Not Displaying In It When I insert an image into a post and link to that image, the link is sending me directly to the file rather than displaying the image via my image.php template. How can I solve this? I haven't been able to find the solution online. This is not a problem with my [gallery] shortcode, which is bringing me to image.php - just with single images.
While inserting the image into the post make sure the Link URL is set to Post URL. !enter image description here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images" }
Wordpress single.php different layouts projects / posts i'm new in Wordpress and I'm currently building my personal website where my works will be published and have a blog too. For the portfolio layout I've looked up this tutorial: < It gives me what I want, more or less. The point is that when I enter on a specific project, the look of it changes a little bit. The file single.php is working right? But doesn't this means that the blog posts will have the exactly the same layout than the project details? I mean, if I edit that file I'm doing it for both blog posts and project details right? How can I make it to look different? Best Regards, Tiago Castro
Install the Custom Post Template plugin and create different templates for your project pages. This works like page templates. You may also consider a custom post type for your projects to use different taxonomies, meta data and templates.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, page template, single" }
Value of Query string How can i get the `total` value from the following URL ` I have this kind of a string query, you'll see that there is a `total=$18.00`, my question is, how can I get the value because I want it to subtract in a number.
If those values are in your query then you can use the following if( get_query_var('total') ) { $total_value = floatval( str_replace( '$', '', get_query_var('total') ) ); } or else if( isset( $_GET['total'] ) ) { $total_value = floatval( str_replace( '$', '', $_GET['total'] ) ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugin gravity forms" }
Rating system and changing the loop Alright, so I want to see who can help me implement this idea I have. I just want one single Icon next to a post. If you click it, then you "Heart" it or "Love it". The post has a counter to see how many people "heart" it. Then I want to change the loop to show off "Trending" posts, "Hot Posts" or something along those lines. Any ideas or suggestions?
The GD Star plugin implements this. It is thumbs up and thumbs down in their parlance but the image sets are configurable. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "loop, rating" }
Advanced Custom Fields Plugin - not displaying images I installed the plugin and assigned it to the relevant page but the problem is that the custom fields display 'no image selected' after I have uploaded them and do not appear on the relevant page. Any ideas? For reference, I have set 'Page Template' as equal to 'Home' (the relevant page) on the custom fields rules. This is the code I am using to call the image on the template: <img src="<? the_field ('image_2'); ?>" class="middle" alt="image2"/>
Did you use the correct format in Advanced Custom Fields when you set up the field? It has an option to return the attachment ID or the image URL when you create the field. So to use it this way you'd have to be sure that it was outputting the image URL not the attachment ID.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, custom field" }
Minimalistic schedular I've been looking at schedulers and appointment maker plugins the last few days, but so far haven't found anything suitable. So thought I'd ask, Basically I just want to be able to list a loads of dates for scheduling games and practices in the admin section and then to display say the next 5 - 10 games and practices on the home page in their own little discreet section/sidebar/widget. Something like this is what I'm after at this site hcusoccer.ca/ at the bottom on the right. Does anyone know of anything that may be good? Everything i've come across so far is probably a bit to big and advanced. Does anybody have any good ideas? Thank you
<
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
Adding all sub-pages to the menu manager Is there some simple way which would allow one to add a page to a menu (through the menu manager interface) and be able to define if the inclusion of this item should automatically add all subpages up to a specific depth? Essentially, the logic I am trying to use here applies to a user adding a new page with content then associating this page as a sub-page of another and by doing so this page automatically shows up on the fronted whenever a specific custom menu is requested where such logic was added. Not sure if the logic of the menu manager allows for such dynamic list capabilities to take place.
There's a plugin for that: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "customization, admin, menus" }
Can't view post, goes to 404 page. Please help I'm on a fresh install of WP and I just made a couple test posts. However, when I click on the post to view the 'single' page, it shows a 404. Furthermore, from the dashboard, when I go to the edit screen for that post and click on 'view post', I get the 404 page again. Any ideas on what can be wrong?
Seems like you're not the first one having this problem, you might want to check WordPress permalinks Yahoo hosting(no .htaccess allowed)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "404 error" }
Custom Permalinks for Posts only I'm using a page as my blog archive, ie < I'd like to list the posts under that url: < I've added Category base "blog" and now my categories appear correctly ( but posts do not. The thing is that I have other custom post types and I don't want the /blog/ part to appear there too. Any suggestions will be highly appreciated.
In case someone else is interested: 1. Removed Category base "blog" since it was conflicting with the actual "Blog" page slug. 2. Changed the permalinks to `/blog/%category%/%postname%/`
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "permalinks" }
Automated posting to wordpress from commandline or XMLRPC API on Dreamhost I operate several wordpress sites on Dreamhost. I have some automated scripts that I want to be able to automatically post to the wordpress blogs. I can do this via a command-line tool or via the XML-RPC. Unfortunately: 1. I can't find a command line tool that will reliably post. (I have shell access on the computer on which the wordpress site is running.) 2. I can't get the XML-RPC API to work. I get an error that I need to use the RPC via POST. I'm told that this is a result of dreamhost running an out-of-date PHP version, but I've tried to use the mods to wordpress and it hasn't been successful. So is there an easy way (or even a hard way) to post to a wordpress blog? Thanks.
Since you have shell access, you could use wp-cli: wp eval-file your-posting-script.php
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "xml rpc, posting" }
How do I create a meta box for dates? I am creating a custom events page and I want to know how to create a custom meta box to save event dates. I don't want it to be a regular meta box because I will be using this to make a custom search bar so I am guessing I have to save it to MySQL no? I am lost, as to how I have to go about this. Any ideas? Thanks in advance.
If you're in need of Meta Boxes for WordPress, check out the amazing code in github by jaredatch. < This allows you to add all sorts of metaboxes to your WP theme (or plugin). Date Picker, file upload, wysiwyg, text areas, text boxes...it's really amazing and saves lots of time.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "metabox, search, query" }
How can I automatically attach posts to a map? I'd like to display a Google map of places relating to posts (eg, places I've visited). Is there a plugin or method available that will allow me to have a Google map on a page and when creating a post, I can put in an address or lat/long for the post, so that it automatically gets added to the map? I'm thinking of something a bit like Drupal's Location module, which adds nodes with lat/longs to a main map.
You could use this plugin, although it may only be compatible to 3.2.1. And this plugin may help you out, although it seems a little complicated to implement a map for all the posts. You could also use a custom field for lat/long on each post, and then create markers using wpdb calls, grabbing the post_meta data, and using the Google Maps API to place the markers, but it sounds as though you'd prefer an out-of-the-box solution. If you do want to attempt this, you might use the above plugin's code as a development roadmap.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "posts, google maps, geo data" }
How can I make the "Preview Post" button save and preview in the same window? When you choose "Preview", which is actually a link, <a class="preview button" href="?p=52&amp;preview=true" id="post-preview" tabindex="4">Preview</a> the post is saved and the preview opens in a new window. I'm sure there is a javascript event attached to this button, I'd like to override it so that it saves and then preview link opens in the same tab / window. !Picture.png
Here's a way to do it without modifying the core: add_action('admin_footer','preview_same_window'); function preview_same_window(){ ?> <script type="text/javascript"> jQuery(function($){ jQuery('.preview.button').unbind().removeAttr('target'); setTimeout(function(){ jQuery('.preview.button').unbind().removeAttr('target'); },250); }); </script> <?php }
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugins, php, javascript, previous post link, previews" }
Simplify the admin end I'm thinking about using WordPress as a content management system for a school. The frontend of WordPress itself would never be seen by the students, but the admin interface would be used by teachers to post bulletins and other messages and news items. Wordpress would then provide an RSS feed to integrate with the schools existing systems. My question is how can the WordPress backend be simplified for use by people with very little technical knowledge. All the is really needed for most users is the ability to view previous posts, and write posts. Can this be easily achieved using some themes or plugins? Or am I better off using another system for this, if so what? Thanks.
First, once you assign users to the role of Author or Editor they will see quite a few fewer menu items (Settings and Appearance goes away) - see Roles and Capabilities. Try creating a second account for yourself and seeing if that helps. You can then remove additional menu items using the Admin Menu Edtior which is a very well written and quite handy plugin. admin-menu-editor-admin-plugins-for-wordpress.jpg If you need more control over roles than that, try the Role Scoper plugin.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, admin" }
Archive with specific keyword by category sorted by date I need help to create a template for an archive with specific a keyword by category sorted by date. This is the code for my archive page so far: < My client wants every navigation menu item to go to an archive page for that particular keyword. Example: "Beauty" navigation location will display the beauty category's posts, sorted by date, using the archive page format. My navigation menu is in the sidebar which you can see here on my site: <
Categories will use category.php by default as their archive template (site.com/category/category-name). Customize that with the code you've used here, rather than using a 'page template'. If you don't want it to say category/ in the URL there are plugins or functions.php code you can use to remove it that can be found numerous times in the archive here.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "pages, archives, sort" }
Load posts from external source if not found in database I want to modify WordPress so that it requests content from a function if content is not found in the database. I want to edit the section of the code which requests and returns the post content from the database so that: if it does not find the content in the database, it calls and gets the content from my function, instead of returning null/not found. I am not sure where this section of the code is or how to go about changing it. I can write a set of functions which return the title/body/excerpt/tags/etc... when give the post id not found in the database. Please help me in finding who/where to make this edit.
Possibly the place to do this would be in the 404.php file of your theme. If there isn't one, create one and Wordpress will pick up. Note: if you want to return "non-404" content from this file you will probably need to clear the headers and set the status to 200. I've done something very similar on other systems and it works fine if you take care to return the correct headers. One word of warning though: you might want to minimise the amount of processing that happens on the this page as otherwise you might end up impacting site performance if you start lots of processing on every single 404.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "posts, database, get posts" }
the_tags only showing when logged in? I'm trying to figure out why the_tags(); when used in the loop are only showing when I'm logged in to the site. I've never come across an issue like this before when developing themes. my code is now on pastebin: < As I said, the tags appear when logged in but only then. Am I missing a permission or some setting that has appeared in WordPress 3.2.1?
The code you posted work just fine , logged in or not . I have confirmed it on my server in multiple locations. There is something else in your theme that is causing it . do you have any other conditional tags there ? like `is_admin()` `is_user_logged_in()` or any other ?? Any plugin you installed while developing the theme ?
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permissions, tags" }
Display an icon based on post type I have a defined set of seven different post types and would like to display an icon for each one in the search results list. I've got the following code to display the post type but have no idea how to extend it into an if <?php $post_type = get_post_type_object( get_post_type($post) ); echo $post_type->label ; ?> Any help appreciated.
<?php $post_type = get_post_type($post); switch ($post_type) { case "type1": echo "<img src='label1.png'/>"; break; case "type2": echo "<img src='label2.png'/>"; break; } ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, search" }
Avoiding "headers already sent" in Wordpress I've created quite a few custom websites but I've come across this problem with various addons/plugins or just general code. How can I avoid the "headers already sent" error? I've tried to put the code as far up in the header.php file as possible but have never managed to get around the error. Is there an easier way to avoid it? My latest bit of code that's getting the error is using the html2pdf script. It always happens in the header.php file, I've removed all extra spaces etc and made sure it's unicode-8 etc but just cannot get rid of the problem in the header.php file.
See WordPress codex page - FAQ Troubleshooting
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "errors" }
get post id using custom filed value I'm having custom field "prime" with values yes or no. I want to get the post id's with selected value " **Yes** ".How can i get that. Thanks in advance
Try something like this $posts = get_posts( array( 'numberposts' => -1, 'meta_key' => 'prime', 'meta_value' => 'yes' ) ); $post_ids = array(); if ( $posts ) { foreach ( $posts as $post ) { // Push post's IDs into array array_push( $post_ids, $post->ID ); } } code isn't tested but it should work. If you don't wont post ids into array just replace whole `array_push` line with `$post->ID` **UPDATE** Set 'numberposts' argument to -1, so it will return all posts not only 5 as default. Thanks to @Brady
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom field, get posts" }
What is a good resource to find out about making custom walkers? Custom walkers seem to be a poorly-documented area of WP. Online tutorials focus on styling the output, not on directing the walker to go where you want it. I am reading the code, but I wonder if there's a good resource I'm missing. If you know about walkers, how and where did you learn about them?
I stumbled across this article, I think it could be of tremendous use to you. It helped me understand it a lot better. I believe there was a question on here in which (I think) @Rarst answered that linked to it, but I can't seem to find it. If someone can find it and edit my answer in place of this that would be great! **EDIT** : Found another pretty good resource you can find here. **EDIT** : More excellent resources below you can look through. I made the ones that are extremely useful in my opinion **bold**! * **< This one in my opinion is the best explanation to modifying the output of the items. It actually also explains what each of the Walker Class functions do. * < This one was a result of the first link, as you can see they link to the first article in this article. :) * ** This has some that I posted above as well as like 5-6 other articles on extending the Walker Class.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 8, "tags": "walker" }
How can I call a PHP function inside a hardcoded shortcode? Maybe I'm doing this the long way but I need to make something like this: <?php echo do_shortcode('[mu-events months="11" startmonth="today" orderby="time" orderas="ASC" sites="?> <?php get_current_site();?> <?php"]'); ?> <?php echo do_shortcode('[mu-events months="11" startmonth="today" orderby="time" orderas="ASC" sites="11"]'); ?> I guess I simply don't know if a function can be inserted inside a shortcode, but in this case it seems like it just has the incorrect syntax. Appreciate any pointing in the right direction! Thanks **NOTE** There is a different between CURRENT_SITE and current BLOG_ID, see my note below
You could do it in this way. echo do_shortcode('[mu-events months="11" startmonth="today" orderby="time" orderas="ASC" sites="' . get_current_site() . '"]');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, shortcode" }
Associating two custom post types I'm trying to a build a system for a client that involves two posts types: "Clients" and "Media Placements." I need a way to associate Media Placements with a particular Client (essentially treating Clients like a category while retaining full post functionality). Each client needs to have many media placements associated with them, and they need to be easily updated. Also, both clients and media placements need full "Post" capability. Meaning editable with TinyMCE, Queryable, etc. Does anyone have any idea what the best way to go about this would be? Any help would be greatly appreciated! Thank you!
There is a neat plugin that might be of use for your task: Posts 2 Post It is capable of establishing relationships between posts and post-types.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, cms" }
Email notification via WP_Mail on published custom post type I've been trying to get an email notification to fire when a new custom post type (in this case, "event"), is published. I've tried a few things and settled down to this simple example that, I imagine, _should_ work just fine. function admin_event_notification() { $message = "Test"; wp_mail( '[email protected]', 'New Event', $message ); } add_action( 'new_event', 'admin_event_notification', 10, 3 ); Any ideas what I'm missing? Once that works, the next step is accessing $post to get the title and permalinks, etc. I think I've got that covered, but any ideas are welcomed.
`'new_event'` is not a default wordpress hook. Hence the above will only work if you include `do_action( 'new_event' );` in your custom post type's saving/publishing function. Your usage of `wp_mail` is otherwise correct. See the codex on `do_action` for reference.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, wp mail" }
Alter the image used for a user who has not uploaded a custom image yet I was wondering if the default image generated for a user in the comment section is "set" somewhere in the WordPress backend. If so, I'm not sure where this setting is. Please see this image to see what i'm referring to: !screenshot of images in comment section The user Jimmy Jacob doesn't have an image yet the commentor Catherine does. Without installing plugins, is there a native WordPress setting which would let me upload a default image to use for this?
Here's a function you can put in your theme's functions.php file to force your own default avatar. Update the $myavatar line to point to your image path/name: // Adds a new default avatar to the list in WordPress admin add_filter( 'avatar_defaults', 'mytheme_addgravatar' ); function mytheme_addgravatar( $avatar_defaults ) { $myavatar = get_bloginfo('stylesheet_directory') . '/images/my-avatar.gif'; $avatar_defaults[$myavatar] = 'New Default Gravatar'; return $avatar_defaults; } Once you've added this function, your new avatar will appear in the list in the WP control panel in the "Settings > Discussion" area. Select it and save. Now if visitors don't have their own Gravatar your new avatar will appear instead. (If you're just looking for how to get your own Gravatar, which will show up on most WordPress blogs/sites in the comments section, go to < and sign up for a free account.) Hope this helps - best of luck!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "images, uploads" }
adding more fields to the comments form including image upload I want to be able to add more fields to the comment form including a date field and a multiple image upload field. I have found a few links showing how it might be possible to add more text fields but how would i allow uploading of multiple photos? When using this contact form the user will be logged in. Ideally I would like to upload the image and have it resized as using WordPress uploader but is this possible as it is on the front end? i do use Gravity Forms but as far as I am aware currently it is not possible to use this with comments? any help will be greatly appreciated thanks
I can explain to you here how to do it , but it is quite long , it evolves many functions,and a long code (even if simple with the new comments form functions and hooks). so the best is just get a plugin that will simplify all. Try this one . , or search others on the same repository . **edit** : this might be more suitable for you than : <
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "comments" }
Remove hovercard for only certian gravatars I am using the Extended Gravatar plugin by Reza Moallemi and it works great. However, on my about page I have a large gravatar to show the author. I would like to know if there is a class I can add to not show the hovercard. Or php that can be added to get_avatar('$email') I could just not include the plugin on the about page but I'm thinking there is an easier way to fix this.
Since @toscho has seemed to have revived this question here is one way to do it (not saying it's the best but it works) It's important to note I've switched to Jetpack which has hovercards built in. If you are using Jetpack here's how you do it. function nifty_remove_grofiles() { if(is_page('about')){ remove_action( 'wp_enqueue_scripts', 'grofiles_attach_cards' ); } } add_action('template_redirect', 'nifty_remove_grofiles'); this basically tells the JavaScript that controls the hovercards not to load on the `about` page.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugins, avatar, gravatar" }
MySQL query performed 4 times inside loop I have enabled custom php in my pages through the use of the `exec-php` plugin so I can run more complex pages than the standard WordPress page. I have had no problems with this plugin so far. I have recently moved a page I was using independently from WordPress to inside the WordPress system. Now instead of running a `INSERT` mysql query once like it should, it runs it 4 times leaving me with 3 redundant rows in my database. As far as I can tell there is no help on this issue, has anybody encountered this problem or know of a way to circumvent this? ~~As it may impact the answer I am using`mysql_query()` in favour of `$wpdb->query()`.~~ EDIT: I have since rewrote the page to use the most appropriate `$wbdb` function (my code can be found here). In addition I found that when I use `$wpdb->flush();` it inserts 1 row only however it seems to break the loop as it doesn't load the template.
Using a plugin to run PHP code inside your content is not the sanest thing to do, especially when said code is not idempotent. Basically, you cannot guarantee that your code will only run once per page load, since several different things in the system may be processing your content, and thus executing your code, multiple times. Instead of using Exec-PHP to store the code in the post content, create a Page Template which contains your code, then attach it to the Page in question. Also, rewrite your code so that calling it multiple times doesn't produce incorrect results (people often double-click buttons and such on the web).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "php, loop, mysql" }
$wpdb->flush(); breaks the loop I am using `$wpdb->flush();` at the base of my page in an attempt to prevent the query executing multiple times due to caching however it seems that it isn't flushing the most recent query but the entire cache as my page is not loading past generating my content. Possibly Relevant information: * I am using the `exec-php` plugin and consequently this page is entirely php * I am also having another possibly related problem as detailed here
In the code you posted in your other question, your call to flush() is using the wrong variable: $wpdp->flush();. Since this is an undefined variable, it's likely that you're simply getting a PHP runtime error at this point, stopping page execution.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, loop, wpdb" }
Add "Post Options" for new wordpress post How i can add "Post Options" section under wysiwyg editor? **Like this**
You must use `add_meta_box` function. Take a look to this tutorials: 1. Using add_meta_box() 2. Tutorial: Creating Custom Write Panels in WordPress 3. Example How To Add Meta Boxes To Edit Area
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "posts, admin, options" }
Notice: Undefined index: filter in ...wp-includes/default-widgets.php on line 382 I'm getting this message on a WP 3.2.1 install with PHP version 5.2.17 Notice: Undefined index: filter in /home/netstewp/public_html/wp-includes/default-widgets.php on line 382 Any idea why?
That a Notice, not an error. Turn off notices in your PHP installation, or turn off the WP_DEBUG mode. More importantly, turn off display_errors. The display_errors setting should never, ever, be enabled on a production site. That's for debugging only.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "widgets, errors" }
i want attachment.php to return the image I use a lightbox to display images from posts in a website that is updated by differents authors. Or course, the lightbox only works if the author makes sure that he uses link to the image directly while uploading the file. 1/3 of the time, the author forgets and the lightbox shows the html of the attachment.php page. Is there possible to have a function, placed into attachments.php, that would return the image instead of the html page ? It would be simple to find the image itself, but I guess this would requires to change headers somewhere so the webserver returns the 'image/jpg' header. I would manage the details but I would need some help to start with. Thank you.
Answer is this (thanks to Wordpress Vampire here : Change Attachment Post URLs to File URLs) : Create an attachment template file within the theme. Since we are only interested in images, the file should be image.php <?php if ( have_posts() ) { the_post(); $image_url = wp_get_attachment_url(); } header('Location: '.$image_url); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "attachments, headers" }
How do i set the read more link? I read the others on the site and i didnt find a working solution. I am using the 20-11 theme and i tried using `<--more-->` (in visual and html) with no luck, using excerpts and whatever i could find. Nothing work I am viewing the page from the root/homepage. How do i make the read more link with just a paragraph or two of text?
try using `<!--more-->` or try the 4th button from the right in the visual editor; or try the 'more' button in the html editor. > I am viewing the page does that mean you are trying to get a 'read-more' in a static page?
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "links" }
Check if a custom post type has already been created I am creating a plugin that creates a new custom post type. How can I check if the custom post type has been created already (maybe by the user in functions.php for some other use)? Actually I would like to know what is the best way to go about it, maybe add a prefix to my custom post type to make it as unique as possible?
To check for the existence of a post type, use `post_type_exists`. For instance like this: if ( ! post_type_exists( 'yourpt' ) { $args = array( // your new post type's arguments ); register_post_type( 'yourpt', $args ) } As for the prefix, that's a matter of personal taste and how common you think the post type otherwise is. Personally, I don't think it's necessary.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, customization" }
Users: List A to Z, for Users I would like to create a list of all the alphabets that represent each user in my site. Example: A -> Link that shows list of all users whose **nickname** starting with letter "A" B -> ...starting with letter "B" C -> ...starting with letter "C" D -> ...starting with letter "D" E -> ...starting with letter "E" F -> ...starting with letter "F" . . Z -> ...starting with letter "Z" I would like to list every alphabet regardless of if there is or isn't a user for it. But would also to know how to only show alphabets with users. Im not sure exactly which method I'll end up using, but I just want to have the option. Ive searched online but couldnt find anything for my particular situation. Id appreciate any help with this. Thanks a lot
There's the WP_User_Query for that: /** * List all Users * Use as: Template Tag * * @uses WP_User_Query * @return (array) List of user objects */ wpse35713_get_users_list() { $query = new WP_User_Query( array( 'order' => 'ASC' ,'orderby' => 'login' ) ); $users = $query->get_results(); $html = "<ul><li>"; foreach ( $users as $user ) { $html .= "</li><li>{$user}"; } $html .= "</li><ul>"; return $html; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "users" }
Facebook profile pic used as avatar I'm trying to add an avatar option for my blog and would like to avoid using Gravatar or custom avatars so I wish to use Facebook profile pic instead of an avatar. I know that there are plugins for that but they're all a bit cumbersome. I tried Incarnate but the issue with it is that there is no authentication so anyone can use any publicly available username thus misrepresenting themselves. Also, if a person doesn't have a publicly available FB profile, they can't use their profile pic. To sum up, I'd like a plugin or a code so that visitors to my blog are automatically represented with their FB profile pic (if they are already logged in to Facebook) without the need for them to register or log in with FB details to my blog. If a person is not logged in to FB, then a custom avatar is to be used. Please suggest a solution.
> To sum up, I'd like a plugin or a code so that visitors to my blog are automatically represented with their FB profile pic (if they are already logged in to Facebook) without the need for them to register or log in with FB details to my blog. There is no possible way to do this. You cannot get somebody's Facebook information without them first "connecting" to your site via a Facebook Application. In short, if you are limiting your question to this condition (the visitor not connecting to your site in some manner and thus granting permissions via an FB application), then it cannot be done in any way whatsoever.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "facebook, avatar" }
Function to return true if current page has child pages I'm trying to create a simple function to do a "status test". Goal is to test and see if the current page being viewed has any child pages or not. Using this to alter layout to accomodate child pages. The following code seems like it should work, but alas, no dice. Anyone see what I'm missing? function is_subpage() { global $post; // load details about this page if ( is_page() && $post->post_parent ) { // test to see if the page has a parent return true; // return true, confirming there is a parent } else { // there is no parent so ... return false; // ... the answer to the question is false } }
Your above function tests whether a page _is_ a child page of some other page, not whether it has children. You can test for children of the current page like so: function has_children() { global $post; $children = get_pages( array( 'child_of' => $post->ID ) ); if( count( $children ) == 0 ) { return false; } else { return true; } } Further reading: * wp codex: get_pages * php manual: count
stackexchange-wordpress
{ "answer_score": 15, "question_score": 10, "tags": "php, theme development, functions, customization" }
How can I (semi) automate a database export and import to a different location? I'm attempting to move toward developing WordPress sites locally, rather than on a live server, and as part of that move I'd like the ability to have a local and a remote version of a site, and easily deploy changes made locally the the remote site. That's easy enough for the filesystem changes using something like Git, but I'm not sure how to make database changes easy to transfer. I understand that it's probably possible to write a script to somewhat automate this process, but I really don't know at all where to start.
Well, I think you've already alluded to the answer. You need to script your database changes. And then run that script on the live database using phpMyAdmin or something like this command if you have terminal access: mysql db_name < scripted_changes.sql If, however, you've referring to **CONTENT** changes then that's a different thing all together. eg If you edit a post on your dev site and want that post change to be applied to your live site, or if you've added and activated a plugin on your devsite. If this is what you want, I am sure there are solutions, but I would recommend you look at your workflow to see if this is necessary.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "database, deployment" }
How to query with get_posts() for posts with any tag I need to do a simple post query that will get any post that has at least one tag. This is my current code that gets the posts with tag ID 27 or 36, but I need to modify it to get all posts with at least one tag. $args = array( 'numberposts' => 5, 'tag__in' => array(27,36) ); $myposts = get_posts( $args );
You could try this. $all_tags = get_tags(); $tag_id = array(); foreach( $all_tags as $tag ) { $tag_id[] = $tag->term_id; } $args = array( 'numberposts' => 5, 'tag__in' => $tag_id ); $myposts = get_posts( $args );
stackexchange-wordpress
{ "answer_score": 9, "question_score": 3, "tags": "tags, get posts" }
hook for dashboard show_user_profile I'm looking a way to avoid regular users go to profile and dashboard page. Have this little code to work with profile page: function lockdown_profile() { global $current_user; return !current_user_can( 'manage_options' ) ? wp_redirect("/profile") : true; } add_action('show_user_profile', "lockdown_profile"); And works, but i need to do the same for dashboard page, any ideas?
`show_user_profile` is the wrong hook to use. You should redirect before anything gets sent to the browser (eg. before headers are sent). Fortunately there are actions that happen much earlier: `load-{$pagename}` is the one you want. So you can hook into `load-index.php` and `load-profile.php` to throw people back to the front end. <?php add_action( 'load-profile.php', 'wpse35742_maybe_redirect' ); add_action( 'load-index.php', 'wpse35742_maybe_redirect' ); function wpse35742_maybe_redirect() { if( current_user_can( 'manage_options' ) ) return; wp_redirect( home_url( '/profile' ), 302 ); exit(); } All that said, you would be better off adding a new role that has even more limited capabilities than the typical subscribers: don't let them view the dashboard or their profiles (the `read` capability).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "functions, dashboard" }
Theming media inserts When I Insert media into my post or page it's rendered as a normal link. Would it be possible to somehow theme links that point to e.g. PDF or other file types?
I think the easiest way would be doing this with jQuery: <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "theme development, attachments, media" }
Get previously visited page ID I would like to get the ID (or permalink) of the page the visitor visited just before visiting the current page - in other words the ID of the last page in the browser history. Can this be done? Any idea how to do it?
Break this down into two parts: First, we create a variable that stores that last-visited page URL, like this: $prev_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; Then, you could either use substr and strpos to trim down everything between _?=_ and the _/_ after the ID number. like this: $prev_url = ' $id_block = substr($prev_url, strpos($prev_url, "?p=")+1); $id = substr($id_block, 0, strpos($id_block, "/")); .. Or, you could use jQuery/Javascript to achieve the same. I haven't tested this but it should work - let me know how it does! Good luck ;)
stackexchange-wordpress
{ "answer_score": 7, "question_score": 7, "tags": "id, previous" }
When to use Wordpress loop or Foreach loop? Under what circumstances would you, (should you?) use a foreach loop, instead of the wordpress loop. I have no real coding need, but I'm curious. What's good practice here? Should I: $args=array( 'post_parent' => $pos_id, ); $sublabels=get_posts($args); foreach($sublabels as $sublabel) { // blabla something to do foreach} Or: query_posts(array( 'post_parent' => $pos_id, 'cat' => 'label', )); while (have_posts()) : the_post() ?> // and then the blabla something for each And why?
Your examples are showing two different thing The first one is looping over categories and the second is looping over posts, so the answer in this case is simple and depends on what you need to loop over (posts or categories). No if you meant when should you use **`query_posts()`** vs. **`get_posts()`** vs. **`WP_Query`** then take a look at this **`awesome answer`** .
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "query posts, loop, customization" }
Best function/method to access wp-config? I have a developer who is accessing the wp-config file directly to get database information. I would think that WP has a better way to do this. What do you think community?
I am not aware of a Wordpress function to do this. But have a look at this search and replace tool: < This achieves what you want by reading in the wp-config file and scanning through it. Have a look at the function "icit_srdb_define_find" on line 374.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "wp config" }
How does Wordpress insert Paragraphs in posts So when looking at the html-view in the editor there is no `<p>` tags, when a view the post every line break is surrounded with a `<p>`. How?
The content is run through the wpautop filter (there's a lot about that on Google).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, functions" }
How can I show more than 15 themes at a time in the admin menu? I have a lot of themes in my test wordpress site. I get a little frustrated that I can't show more than 15 at a time. Picture.png In pages and posts you can click "screen options" to choose the number, but it looks like "Themes" has no such option. Picture-1.jpg Is there another way to increase the number?
It's hardcoded into the `WP_Themes_List_Table` class that's responsible on Line 50. $per_page = 15; So in short, you can't without modifying a core file. Link to source.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "themes, admin, filters, theme options, user interface" }