INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
Woocommerce blank screen variable product attribute image thumbnail I am using woocommerce, I have setup a variable product. Under each attribute, when I try to add a thumbnail image by clicking on the Insert Into Post button for the Media Uploader dialog, the dialog box becomes empty without any content. In the javascript console in Google Chrome, I get the following error: post.php:1310 Uncaught TypeError: Cannot call method 'replace' of undefined Any ideas? Thanks!
I can confirm this was fixed in WC 1.5.2 :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "media, plugins" }
How can I test how fast or slow my wordpress website it? I have my FIRST wordpress website and I love it, however I'm not sure if it's my browser (Firefox 8.0.1 for Mac) or my computer or the website itself but it's going really slow. MY SITE is in the finalizing stages and I want to make sure it's smooth. This is my first wordpress site so I can see myself adding a lot of things and maybe slowing it don that way? First off, is it slow for you guys? Where is a good site, plugin or article about how to determine how slow/fast your wordpress site it? Is there a handy plugin that can speed it up? Is there somewhere I can check to see how big my site it? What might be a specific thing slowing it down?
Try Pingdom.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 6, "tags": "css, performance" }
WordPress 3.3.1 single post template Does anybody have any idea why on single posts there are no template dropdowns for template selections in WP 3.3.1? I did not find that either in the page administrative area. Thank you
For page templates, click on screen options in the top right corner and check the Page Attributes box. If your theme has no page templates to choose from then the template drop down will not be shown. Posts and other post types do not use or support page templates and never have. Only pages support them out of the box. You can install plugins however that let you have custom post templates. There is also the post formats feature.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "templates" }
Hiding the media-new.php File URL option via jQuery As the title says I'm currently having some difficulties hiding the File URL option via jQuery. I've been trying this: // add_action( 'admin_footer-media.php', 'cor_remove_tr_file_url' ); add_action( 'admin_footer-media-new.php', 'cor_remove_tr_file_url' ); /** * Removes the 'File URL' row */ function cor_remove_tr_file_url() { ?> <script> jQuery(document).ready(function($){ $('tr.image_url').remove() }); </script> <?php } which works great on `media.php`, but somehow it isn't working on `media-new.php`. Would someone perhaps know what I might be overlooking here? !enter image description here
This is because those elements aren't present when the page is finished loading, they're inserted later on using javascript. Try hooking into #media-items and running your code when new elements are inserted rather than when the root element is ready.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "admin, jquery" }
Why is a 500 error generated by admin-ajax.php not going into the Apache error log? I'm getting 500 errors with AJAX on the admin side. However, these errors aren't being logged in the Apache logs so they're rather hard to debug. Is there some way I can find out what they are? Thanks
Sometimes I have a 500 error ( from NGinx ) just because I have a "character" getting outputted before the first header gets written ( or in-between ). Activate WP_DEBUG = true and see what happens. 99% of the case I could spot the error from there. ( and it was nearly all the time the above error ). Post back if that doesn't solve your debug difficulty problem. We'll have a look at your apache config by then.
stackexchange-wordpress
{ "answer_score": 13, "question_score": 5, "tags": "ajax, 500 internal error" }
Custom php page in WordPress theme? For example I have in my theme folder named test-pages with some php web pages that display different message, in some part of process I want to pull with file_get_contents to get content of one page from that folder, but I can't do it, it just doesn't work, when I try to access directly to that page, I get 404 message like that pages doesn't exists. How can I make this page visible to WordPress, so I can access it without getting 404? Hope you understand me.
Move the template files out of the subdirectory, and put them in the Theme's root directory. Then, if you simply want to include the contents of those template files in _other_ template files, simply call `get_template_part( 'test-page-name.php' );`. If you _insist_ on keeping these files in a subdirectory, you'll need to include them via `locate_template()`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "theme development, functions" }
How do you hide images from posts only As the title says I want to keep images on pages and hide them from posts on my site . How can I do this? Thanks
You can do this with a css solution. Pages and posts have different `body_class`es, so you should be able target them with `page` and `post` respectively. Your CSS would look something like this: .post img { display: none }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "images" }
How to associate an existing user to a site in a multisite setup programmatically In a multisite setup, you can associate an existing user in the network to a site. The standard wp_insert_user function doesn't seem to have the proper logic to handle. How would I do this for multisite? Also, is there a way to see if a given user is already associated with a particular site?
After looking the code the create user, i found that that I can do: $userdata = get_user_by('login', 'user1'); add_existing_user_to_blog( array( 'user_id' => $userdata->ID, 'role' => 'author')); Fix: was missing closing )
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "plugin development, multisite" }
Settings API - getting hidden input / submit button's name I'm generating this form using Settings API: <form action="options.php" method="post"> <?php settings_fields('XX_theme_settings'); do_settings_sections('my_settings'); ?> <input type="hidden" name="foo" value="bar" /> <input name="SubmitButton" type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" /> </form> Validation callbacks $input array returns only 'my_settings' input fields. How do I access `foo` (`bar`) input's value and submit button's name `SubmitButton`? This doesn't work for the hidden input: my_validation($input) { $foo = $input['foo']; } And when it comes to the submit button I don't even know where to start.
Using `$_POST` is too low level. Simply give it the same name as your other options. When you options are displayed they should have the names of the form: `my_settings[a_particular_option]`. For instance: <input name="my_settings[some_input_option]"/> Then for your hidden input and submit button: <input type="hiddden" name="my_settings[foo]" value="bar"/> <input name="my_settings[SubmitButton]" type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>"/> In your validation array my_validation($input) { $foo = $input['foo']; $submit = $input['SubmitButton']; }
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "validation, settings api" }
How can I create an upload page for (and only visible to) specific users? I'm working on a WordPress site we have for some software my lab is developing. What I'd like to do is add a page that would allow collaborating groups to upload their data to us for testing, but that would be hidden from anyone else visiting the site (i.e. the collaborators would have to be logged in to see the page). Ideally they wouldn't see the dashboard when logged in, but that's not too much of an issue at the moment. Are there any plugins that would make this easy?
The plugin Omni Secure Files has quite a nice upload interface and different wordpress user roles can be given permission to either upload or just view the uploaded files **Update from comment** Here's the code I put into a page template to get the basics of OSF working in the front of the site: if (!empty($omni_secure_files)) { wp_register_style('omni-secure-files',$omni_secure_files->plugin_url.'css/style.css',array(),false,'all'); wp_enqueue_style('omni-secure-files'); $omni_secure_files->menu_root(); } The `wp_register_style / wp_enqueue_style` is necessary if you want to style it nicely. You mostly need to copy the required admin styles into the page template. At some point I might get round to releasing it as an extension to the plugin. I think the folks that wrote the plugin will probably get round to it at some point. It did take a lot of work though, so its no easy fix.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "user access, uploads" }
How can I force the Wordpress visual editor to preserve the line breaks after paragraphs? If I write and put a line break, it make the paragraph tags appropriately, but on this one page the line breaks aren't there: <
The editor is doing fine to add `<p>` tag on line break. I think what you need is to add some css to add margin to `<p>` tag so you don't have to add additional or empty paragraph tags (which i see on your current page). try something like this on your css: .entry-content p{ margin: 10px 0; } That should give you a nice margin on top and bottom of the paragraph tag. Also you might want to add some margin on `<ul>` and `<li>` to get a good formatting. Hope it helps. Let me know if you have any questions.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, editor, line breaks" }
How to style the RSS wordpress? I am using the default rss feed widget but want to style it. My question is -where to add my piece of code to style the default wordpress rss widget?
You will need to add XSLT sheet to the RSS declaration. It will automatically beautify the RSS XML. You have a tutorial here Otherwise, just use "Advanced RSS" plugin, that allows you to configure the graphics with it ( via XSLT ). Plugin page here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins, widgets, css, rss" }
Add jQuery function to media button I have added a custom button to the media actions in a custom theme, function wp_myplugin_media_button($context) { $wp_myplugin_media_button_image = '../wp-content/themes/datamine/images/icon_create_table.gif'; $wp_myplugin_media_button = ' %s' . '<a id="fluffyRabbit" href="javascript:;" title="Add a Tabletool table to the post."> <img src="'.$wp_myplugin_media_button_image.'" alt="" /></a>'; // table.php?type=tabletool&amp;TB_iframe=true" class="thickbox" return sprintf($context, $wp_myplugin_media_button); } add_filter('media_buttons_context', 'wp_myplugin_media_button'); but how can I attach event listeners? $('#fluffyRabbit').live('click',function() { alert('o hai!'); }); If I use add_action, do I have to include a new `script.js` file? If someone can step by step me on this that would be awesome. I just started really tinkering with WP. Cheers! Bo
I got it to work after playing around for while... this went in the custom js file jQuery(document).ready(function(){ jQuery('#fluffyRabbit').live('click',function() { console.log('o hai!'); }); //console.log('loaded'); }); this went in functions.php function load_scripts() { wp_enqueue_script('jquery'); wp_enqueue_script('ttcustom', '/wp-content/themes/twitunez/ttcustom.js', array('jquery')); } add_action('init', 'load_scripts');
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "jquery, menus, javascript, media library" }
How to remove the tagline from the HTML <title>? I'm using the default Wordpress 2011 theme on a new blog I'm setting up. I've got everything basically setup fine for now. I have experience with PHP/MySQL and HTML/CSS, but haven't used WordPress as yet. When I set the blog up, it asked for a tagline under general settings, which I provided. This is showing below the blog heading, which is fine, however I don't want it to appear in the HTML title. At the moment the `<title>` element looks like this: "Blog Name | Tagline". I just want the blog name. How can I change this?
Ah, figured it out. In `/wp-content/themes/twentyeleven/header.php`, you can comment out this: // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) echo " | $site_description"; Then the blog tagline won't be added for the front page.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "customization" }
How to make number of blog posts a custom field? I'm using advanced custom fields and I have the following code: <?php $args = array( 'numberposts' => 3 ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?> Where the number of posts = 3, I was wondering if I could turn this into a custom field in the editor so that my client can easily change how many posts per page should display. Now using my 'simple this is how it should work' PHP brain, I thought I could use the following: <?php $numposts = <?php the_field('number_of_posts', $number_of_posts); ?>; ?> But it doesn't quite work. Any tips? Thanks.
It might actually still work, but the syntax is currently wrong (you have a PHP opening tag inside another opening tag). And you can assign the value of the custom field to a variable using the `get_field` function. What if you try this? <?php // assuming your ACF name is 'number_of_posts' $numposts = get_field('number_of_posts'); $args = array( 'numberposts' => $numposts ); $lastposts = get_posts( $args ); foreach($lastposts as $post) : setup_postdata($post); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, php, blog, customization" }
How do I know if author field was changed on post save? I'm writing a plugin that sends notifications on various post events. One of the notifications should be sent when a post is assigned to a different author. How can I know that the post author was changed ?
Best Hook for that would be **`wp_insert_post_data`** function wpse44358_filter_handler( $data , $postarr ){ //do your stuff //if ($data['post_author'] == ... return data; // make sure you return something } add_filter( 'wp_insert_post_data' , 'wpse44358_filter_handler' , '99', 2 );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "filters, actions" }
Fixed height of the_content() I have page with news. I'm displaying them as a shortened text (300 chars limit), I'm removing any images using preg_replace() and everything looks fine, until someone uses line breaks in his post. Things gets messy then and my height is way to high sometimes. Ofc I'm using `overflow: hidden;` but its not as good as I would like it to be. Is there a way to trim out those spaces, remove `<strong>` if someone uses it etc.? So my news page looks always as awesome as it should? Cheers
If you run a `wp_kses()` on `the_excerpt()` (through a filter) you can whitelist specific HTML tags and such. In your case, the code would probably look something like this: if( is_page( 'your_page' ) ) { add_filter( 'the_excerpt', 'wpse44363_filter_the_excerpt' ); } function wpse44363_filter_the_excerpt( $excerpt ) { // this allows no html, you can allow only links or something of that nature $allowed_html = array(); return wp_kses( $excerpt, $allowed_html ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "css, the content, characters, limit" }
Local wordpress setup with SPAM in the incoming links dashboard section? I am developing a website on my localhost and i just notice a bunch of incoming links in the dashboard's incoming links section, which doesn't look valid. When i visit the urls i don't see a reffer to my localhost/domain.com. the only plugin i had active was "Regenerate Thumbnails". I disabled the plugin but i can still see the links. How can i fix this? regards
The incoming links widget is asking Google for links to the domain you’re on right now. If your domain is `localhost` you get a lot of links – because that’s a very common domain name. Unfortunately, some people don’t clean up their data when they move from localhost to the world wide web, and then Google will find these links. :) Nothing to worry about.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 4, "tags": "dashboard, spam" }
wp_mail is undefined I am writing a plugin that opens up a form to invite people to a website by email and want to use `wp_mail()`. Whenever I use the `wp_mail()` function in any file in my plugin folder I always end up with: PHP Fatal error: Call to undefined function wp_mail() The code segment in question is: function send_email() { $subject = 'test'; $message = 'this is a test from send invitation'; $to = '[email protected]'; wp_mail($to, $subject, $message); } I am at my wits end as to why this should be happening when so many plugins use `wp_mail()`. Thanks in advance.
You may call the function too early. You have to wait until the action `'plugins_loaded'` fires. `wp_mail()` is defined in `wp-includes/pluggable.php`. `pluggable.php` is loaded in `wp-settings.php` _after_ the plugins are loaded but _before_ `'plugins_loaded'` is called. See this answer for an example.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 4, "tags": "plugin development, wp mail" }
How to Use the Function is_user_logged_in To Display Different Menus? So, I want to create different menus for people who are logged in or not. I got a reply that i should use a function if (is_user_logged_in()) { wp_name_menu(array('theme_location' => 'logged_user' )); } else { wp_nav_menu(array('theme_location' => 'new_user' )); } So, if I get this right, I put this into `functions.php` which is located in my child theme (anywhere inside the file?), then I create another menu and where it is "logged_user" and "new_user" I enter the names of the menus?
i just did this for a site i am working on. first i registered 2 menus in functions.php: add_action('init','kia_menus'); function kia_menus(){ register_nav_menus( array('primary-menu' => __( 'Primary Menu for Logged In Users', 'kia_theme' ), 'primary-loggedout' => __( 'Primary Menu for Logged Out Visitors', 'kia_theme') )); } and then where i want the 1 menu to appear based on the user's status (probably in header.php but depends on your theme): if( !is_user_logged_in() ){ wp_nav_menu( array( 'theme_location' => 'primary-loggedout' ) ); } else { wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, customization, menus" }
Moving WP install from local to live, what about wp_posts GUID? Done this before and i am still wondering what to do with the `wp_posts => guid content`, which has reference to But at wordpress.org documentation it clearly states: > Never, ever, change the contents of the GUID column, under any circumstances. But as i understand it is just to unique identify your posts globally. But as more people would have in their guid. So can i safely replace with < ? regards
"GUID" stands for "Globally Unique Identifier" mainly used by feeds to tell if that specific post was shown on the feed before or not, even if you change domains. When developing on local host and the moving to live (+1 just for that BTW) and no feed reader/burner has read your feeds and only if that is the case it's OK to change it and start fresh on your new live host.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 14, "tags": "customization, guids" }
wp redirect 301 not working in wordpress page < on my wordpress page i have a form and i am redirecting my wordpress page to some other website after form submit i have following code in my functions.php file for submitting form. add_action('init', 'redirect'); function redirect(){ if(isset($_post['submit'])) { wp_redirect("www.google.com",301); exit(); } } but its not redirecting and showing 404 error and following url on submit < here i am using shortcode to display form on my wordpress page. what is the reason? any clue?
You need to place http:// in front of the URL for wp_redirect to work properly.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, redirect" }
When I change slug, will WordPress create redirect from the old URL? When I change a slug from `post-a` to `post-b`, will WordPress create a redirect from `/post-a` to `/post-b`, like HTTP 301 or something similar? If not, is there a plugin for that?
I just went and tested this (WP 3.3.1), the wordpress core will automatically do a redirect if you change the post slug, even if you change the slug from `post-a` to `post-b` and then to `post-c`, `post-a` will return a 301 to `post-c`. That said, the redirection plugin that Mike Jolley recommended is an outstanding plugin and a great way to monitor for 404 errors and such.
stackexchange-wordpress
{ "answer_score": 14, "question_score": 19, "tags": "redirect, slug" }
What plugin(s) are best for this User registration task? I have a site with user registration and I have a few specific qualifications that I must fulfill. 1. The login/registration area should be on its own page within the template using a custom page template (im going to use jquery tabs for login/reg); i dont want to use the regular wordpress signup/login page. 2. I must be able to add extra fields to the registration process (phone, address, etc) 3. I'm already using simple facebook/twitter connect so that's taken care of, but it should be compatible with that (although i dont see that as a problem as it seems to take care of everything separately) 4. it needs ability for captcha
Gravity Forms is a premium one, but was the only one that solved without flaws a custom registration I needed to implement... Appart from the _Premium_ part, I have to inform that only the _Developer_ licence will give you access to the **User Registration** extension. If you go past the Premium-Developer issue, check their forums as there's a glitch with the _nickname_ when registering users.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, login, user registration, signup" }
Loading scripts on a single page plants the script in the footer I'm using this code to plant a script on a spesific page, it works but inserts the script into the bottom of the page not the top - I'm at a loss to explain why! Is there a way to do this that results in the script being inserted inside the head tags. function single_page_load() { if ( !is_page_template( 'interactive-map.php' ) ) return; wp_enqueue_script( 'map', get_template_directory_uri() . 'jquery-map/map.js', array('jquery'), '1.4.2', true ); } add_action( 'template_redirect', 'single_page_load' );
`wp_enqueue_script` accepts 5 parameters. The fifth one is `$in_footer`. If that parameter is set to true the script will load in the footer. If it is set to false it will load in the head, **unless** a dependency (like jQuery in your code) is set to show up in the footer.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "jquery, javascript, wp enqueue script" }
How do I amend the fixed "author" part in the URL? I am creating a localized instance of WordPress and one can easily configure the category and tag parts of the URL but I cannot find anything similar for authors. So for instance I get this: instead of which would be appropriate in my language. How to achieve that? (And BTW, can "borekb" be replaced with something like "borek-bernard", i.e. full name slug instead of username?)
Use the plugin Edit Author Slug: > This plugin allows an Admin to change the author slug (a.k.a. – nicename), without having to actually enter the database. You can also change the Author Base (the ‘/author/’ portion of the author URLs). Two new fields will be added to your Dashboard. The “Edit Author Slug” field can be found under Users > Your Profile or Users > Authors & Users (Users > Users in WP 3.0). The “Author Base” field can be found under Settings > Permalinks.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "urls, localization" }
Using catch_the_image to get the thumbnail size I use front end posting on my site so I don't get a chance to set a featured image for alot of my posts. So I use catch_the_image to get thumbs but it gets the original size and then scales it which is hurting page speed. Basically what I want to do is add "-150x150" into the string in the function so it pulls the smallest size of the 3 it stores in the uploads folder. So instead of picture.png it returns picture-150x150.png. Any idea how to add that to this function? function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=\'"[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; return $first_img; }
You can add your own named image size by adding code to your functions.php. Something in the line of add_theme_support('post-thumbnails');//might not be necessary add_image_size('front-end-150', 300, 300); Now you should be able to use in your catch_that_image() wp_get_attachment_image($post->ID, 'front-end-150') for all newly uploaded images. Your past images don't have the front-end-150, so you might want to use the regenerate thumbnail plugin ( Good luck!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails, cropping, scale" }
body_class hook for admin pages The body_class hook seem only to work with non-admin pages. When I do add_filter('body_class', 'add_body_classes'); function add_body_classes($classes) { $classes[] = 'myclass'; return $classes; } Is there another hook i should be using if i want to add a class to the body of an admin page?
Admin pages don't use the `body_class` filter, use the `admin_body_class` filter to add classes to admin body tag instead. Note that `$classes` in that case is a string, not an array.
stackexchange-wordpress
{ "answer_score": 25, "question_score": 21, "tags": "plugin development, admin" }
Building custom pages with a video player Hey i am trying to learn wordpress developement on my own, I'm building a celebrity gossip blog and i need help. I want to build a video page. Does anyone know of a plugin or anything that i can use that allows me to have a flash video player that also accepts youtube links as well. Something like, Inserting the video url, youtube if needed, and information about the video, and when i'm done i save it, and it has it's own video page that i can link to. for example this link below has a list of video post: < and when you click on the links it goes to a single video page like the link below < Or would i have to create a special post type for videos. I would deeply appreciate it if someone could give me an answer to this question, it would make me extremely ecstatic.
Have you had a look at Tubepress - < ? Then you could create a new category and a custom layout for that category.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, functions, attachments, video player" }
How to make this plugin more efficient Hi I have this plugin < which imports feeds from various websites. There are two problems I would like help in solving. The first is that I would like to place a limit on the date of the oldest feeds retrieved, limiting all results to the last 7 days. Secondly when I add more than 10 feeds it really starts to slow down the page and gets me PHP timeout errors. How can I make it more efficient, so it doesn't require huge load times on every page load? Thanks.
Instead of checking and updating the feeds every time you do the shortcode, instead register cron tasks for each feed timed to their update schedule. Also saving the feed items as posts, and storing the GUID in the posts meta, then only saving the feed items that are new, will simplify things. It will also let you use WP_Query on posts instead of dealing with feed transients too.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "rss" }
Function to get permalink of custom post type archives? Is there a function that will return the permalink to a custom post types archives that is available to use in WordPress? Something like: `get_cpt_permalink("events")` which will return ` when `has_archive => true` on it. If not what would I need to home brew my own? I'm thinking I would need to read `$wp_rewrite` and use something along the lines of `$wp_rewrite->get_extra_permastruct('events');`
This is what you are looking for `get_post_type_archive_link( $post_type );`
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "custom post types, permalinks" }
Customizing page content layout For a while now I have been building WordPress based sites for clients. These sites tend to be brochure sites so feature a collection of pages all with slightly different layouts within an overarching main layout and style. Upto this point I have either created Pages in the WordPress admin panel and then created a page template with the content embedded into it (not great when the client want to be able to update the page) or created a new page and a generic "page" template and then placed content into this using HTML in the editor (not great for the user trying to edit the content in the editor, or when the editor decides to add more HTML tags) Is there another way to easily create pages where the user can easily update the content using the editor but wont risk screwing up the layout? something like multiple editors or content areas in the admin panel?
Disclaimer: I have no affiliation with this plugin nor its author, it's just a plugin I've found to be indispensable in my Wordpress tool kit. So this is not an advertisement for a plugin. The plugin you want is: Advanced Custom Fields. It's a free plugin that'll make your life a lot easier for varied post editing pages and whatnot.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "themes, pages, customization" }
PHP Syntax Error on get_posts I have the following coding: <?php global $post; $args = array( 'numberposts' => 8); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post);         echo '<a href='.the_permalink().'>'.the_title().'</a><br />';         endforeach; ?> Dreamweaver is highlighting a potential syntax error on line 6 & 7\. I'm sure it's something very very simple but can someone point me in the right direction to solve this error please?
Not sure if it is causing Dreamweaver to flag an error (try running it?), but on the second from last line you want to be using `get_the_title()`. This returns the posts' title, whereas `the_title()` will echo it. echo '<a href='.the_permalink().'>'.get_the_title().'</a><br />';
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "php, get posts" }
get_meta_data within a loop I'm trying to make a simple widget that displays a list of posts, and is followed by some metadata from each post. Here is my code: `$eventdate` contains the metadata i need to retrieve. query_posts(''); if (have_posts()) : echo "<ul>"; while (have_posts()) : the_post(); $eventdate = get_post_meta($post->ID, 'event-date', true); echo "<li>".get_the_title()." - ".$eventdate."</li>"; endwhile; echo "</ul>"; endif; wp_reset_query(); I read an old post on the wordpress support forums about custom loops like this, and I'm fairly certain that I'm not calling the $post_id properly, because if I manually insert a post_id it calls the correct data.. but either way I'm unsure where to go from here. Any help would be appreciated.
`query_posts()` is for main query, it would be more wise to use `get_posts()` function to get you events. // Modify get_posts args for your needs $events = get_posts( array ( 'post_type' => 'events' ) ); if ( $events ) { echo '<ul>'; foreach ( $events as $event ) { $event_date = get_post_meta( $event->ID, 'event-date', true ); echo '<li>' . get_the_title( $event->ID ) . ' - ' . $event_date . '</li>'; } echo '</ul>'; }
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "query posts" }
How to use images uploaded with custom implementation of thickbox like the_post_thumbnail() functionality I have create a custom post type with meta boxes. In metaboxes I have create some fealds that the use can use the WordPress ThickBox Media Dialog to upload his/her images for each post seperatly. From the other side, the WordPress, when I upload an image as a Featured image, gives me some functions like the the_post_thumbnail() that allowing me to choose the image size that I need in my template. So, the question is, can I use any function looks like the above one to print out the image sizes I like, that the end user has upload through the media box custom fields ?
If you're not opposed to using a plugin to achieve this, I would recommend the Multiple Post Thumbnails plugin. It's very simple to use and provides the same functionality as "the_post_thumbnail()" function.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "post thumbnails, thumbnails, thickbox" }
What's the internal concatenation function for creating Excerpts with Wordpress? I'm already familiar with the_excerpt() and get_the_excerpt() functions. These two functions relate specifically to some node/taxonomy/whatever (post, page, custom post type) inside of Wordpress, unless I'm mistaken. What if I have some external text, and wanted to pass it through a concatenation function. Does anyone know the function to do that? What I'm trying to avoid, is creating a new function or re-writing an old function to limit words inside of a string. For example, > echo some_excerpt_function($text, $amount_of_words_to_limit); I'm assuming Wordpress has something similar to this, that's why I'm asking.
Use `wp_trim_words( $text, $num_words, $more_text )` The first argument is the text to trim, the second is the number of words you want and the third is the truncation text which defaults to an ellipsis. The function is located in wp-includes/formatting.php line 1920 (v3.3.1)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "excerpt" }
Show a different code on front page to other pages I'm looking to display a list of posts in the header section on my template on all pages with the exception of the front page where I would like to show an image in place of the list of posts. Is there a function within wordpress to detect the front page that I can use in my template code? or should I just be looking at PHP code that says if the URL matches X then show this, else show the other code?
You can use the wordpress template hierarchy to do just that. Specifically, you can put the code you want in `front-page.php` and then use `index.php` for the rest of them, though that's a rather bland way of doing design with what you have on your hands. Alternately, there are the wordpress conditional tags which can be used to detect whether you're on a category page or the frontpage, etc. ### Edit Using the `is_front_page()` conditional: <?php if ( is_front_page() ) { // This is the site front page; // put your front-page output here } else { // Put your default output here } ?>
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "php, templates, frontpage" }
E-commerce for wordpress Is there an e-commerce solution for wordpress which will allow a shop with an onsite blog? If so, what are the options and is there generally one thats considered the 'best'?
I highly recommend WooCommerce. Those guys are brilliant. It's based off of Jigoshop another great solution. To me, though, WC is one of, if not, the best solutions for WP e-commerce. Great support. Great themes. Uber easy to integrate with a custom theme as well.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 0, "tags": "plugin recommendation, e commerce, plugin wp e commerce" }
Populate wordpress menu with link to custom field value (file download) I have an additional menu that appears on some single.php pages. To this menu I would like to add an li with a link to a PDF which is uploaded to the post by a custom field (advanced custom fields helps with this). I found a snippet on how to add todays date to my menu, and thought I could maybe use this as a starting point. However I´m not good enough coder to know where to go from here. I would appreciate some help with it! This is the snippet I´m starting with: < I need to make it display this instead: <a href="<?php the_field('mcf_uppsagning-pdf'); ?>">Uppsägning</a> I cant just replace it though and I dont know the syntax enough to know how to modify it. Please help :) Thanks
Try this: // Filter wp_nav_menu() to add additional links and other output add_filter('wp_nav_menu_items','add_pdf_to_menu', 10, 2); function add_pdf_to_menu( $items, $args ) { if( $args->theme_location == 'extra-menu') { $pdf = get_post_meta( get_the_ID(), 'mcf_uppsagning-pdf', true ); if ( $pdf ) $items .= '<li><a href="' . wp_get_attachment_url( $pdf ) . '">Uppsägning</a></li>'; } return $items; } Essentially because you're in the context of the single page `get_the_ID()` will return the id for the post/page you're on. If that doesn't work try using `get_queried_object_id()` in place of `get_the_ID()`. EDIT: changed the above code to return the attachment permalink.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, menus" }
Replace image urls(absolute instead of relative) by using filter in single page I'm using a plugin called Foliopress WYSIWYG. While using this plugin, images found in the_content loop using relative image path instead of absolute paths. So all the feed images looks broken. This plugin stores images in ` folder instead `wp-content/uploads` folder. So i would like to use filter to replace relative path. I mean if any img src file looks like `/images/2010/03/example.jpg` then it should be filtered and replaced with ` Can anyone give me the snippet? Thanks
Something like this should do it, you may have to fiddle with the `preg_replace()` to get it to work the way you need, but the concept (and, more importantly imo, the regex, is there). if( is_single() ) { add_filter( 'the_content', 'wpse44503_filter_content' ); } function wpse44503_filter_content( $content ) { $regex = '#src=("|\')'. '(/images/(19|20)(0-9){2}/(0|1)(0-9)/[^.]+\.(jpg|png|gif|bmp|jpeg))'. '("|\')#'; $replace = 'src="'.get_site_url( $2 ).'"'; $output = preg_replace( $regex, $replace, $content ); return $output; } That's untested, and I wrote it right into the solution box, so make sure you debug thoroughly and such.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins, rss, images, paths" }
Need help with adding templates (archives and sitemap) to Wordpress child theme I recently switched themes, and my old theme had templates for sitemap and archive (in fact the archive was one of my most viewed pages.) When I switched themes the link to the archive and sitemap page still works, but they are blank pages. I really need to get this fixed, and I have no idea how. I'm assuming I need to recreate a new template in the parent theme for the sitemap and archive page (I'm using a child theme). I've never created one before, and with my old theme it was very simple since I could just use the template. Could someone help me get this up and going on my new theme? Thanks.
I ended up just using the template that Wordpres.org provides. Everything seems to be working fine now. thanks!
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "theme development, templates, pages, page template, child theme" }
The 'https_local_ssl_verify' filter I have run into some WordPress code which does POST requests to API sites and in the POST parameters for the SSL property it has $params = array( 'body' => $_POST, 'sslverify' => apply_filters('https_local_ssl_verify', false)); So why not simply put false or true?
The `apply_filters()` function lets plugins and themes override the value. So yes, you _could_ manually set `sslverify` to `false`. The code snippet you included will set it to false _in the absence of any filter._ Let's say I have a plugin that wants to force it to true. I would add this: add_filter( 'https_local_ssl_verify', '__return_true' ); The `__return_true()` function is a special function in WordPress that automatically returns `true`. So if I add this code to a plugin or my theme's `funtions.php` file, it will force your code above to set `'sslverify' => true`. It all depends on your local setup and what you're trying to do with the site. The use of `apply_filters()` merely makes things as flexible as possible.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 1, "tags": "posts, security" }
Reblog wordpress.com posts on self hosted I'm currently collaborating to a wordress.com blog and would like to use the reblog feature to mirror my posts there to my main blog that is a self hosted wordpress installation. My understanding is that this is only possible within wordpress.com so I searched for some plugins to accomplish this and the closest I came to it is the "Press This" feature, but it's not a good solution because it's mostly copying and pasting the text from the other post and it seems to fail to import links, youtube videos and other things. Is there some way to do this?
Try something like < or another RSS aggregator.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "wordpress.com hosting" }
How to list post as buch of category, and all of them I like my homepage not to list only one category, but to list all category, group by post. Here is the request : Cat * 1 * 2 * 3 * 4 * 5 and the post will be : post * 1 (cat=2) * 2(cat=2) * 3(cat=1) * 4(cat=3) * 5(cat=4) * 6(cat=4) * 7(cat=4) * 8(cat=4) * 9(cat=5) i like to list cat : 5,2,4,3,1 and when listing them, all the post from cat 5, then all the post from cat 2, and so on So the result will be post : * 9 * 1 * 2 * 5 * 6 * 7 * 8 * 4 * 3 hope the example is clear enough to let you help me... thanks in advance
here is a general structure how I would do it: $categories = array(5,2,4,3,1); //manually enter the array of the category ids in the order how you want them to appear foreach( $categories as $cat ) { $args = array( 'category__in' => array( $cat ), 'posts_per_page' => -1 ); $cat_query = new WP_Query( $args ); if( $cat_query->have_posts() ) : while( $cat_query->have_posts() ) : $cat_query->the_post(); //enter here, whatever you want to show per post// endwhile; endif; } //end of foreach
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, categories, sort" }
Why is "/page/2/" not working? Finally got pagination to work with the below code, but now the pagination links to /videos/page/2/, which doesn't exist. How do I get page 2 to work? <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('post_type=videos&showposts=1'.'&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); //display stuff endwhile; php wp_pagenavi(); ?>
Found the answer: > After a looong day debugging thru wordpress core, I managed to solve this issue. > > Basicly, you CANT have a PAGE and a CUSTOM POST TYPE with the same name. If you do, the permalink rewrite rules will get confused and trigger a 404. > > A very simple solution I'm using is: The page that lists the custom post types is called in plural (eg. products) and the actual post type name is in singular (eg. product). So they dont conflict and it's all fine. > > Done Done! Hope this will save people's time. * via rafaelxy (<
stackexchange-wordpress
{ "answer_score": 20, "question_score": 14, "tags": "permalinks, wp query, pagination" }
Random Custom Post Type Titles So i found the code below from another question on here, it displays a list of titles from a custom post type, my question is, How do i get the list to randomize? <?php $queryObject = new WP_Query( 'post_type=announcements&posts_per_page=5' ); // The Loop!if ($queryObject->have_posts()) { ?> <ul> <?php while ($queryObject->have_posts()) { $queryObject->the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php } ?> </ul> <?php } ?>
`WP_Query` has an `orderby` property which can be set to `rand`. If you change your query string to `'post_type=announcements&posts_per_page=5&orderby=rand'` you should be good to go. You might want to take the time to read through the whole documentation for `WP_Query`, just so you're familiar with its capabilities.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, get the title" }
How to disable sidebar only in bbPress and not WordPress? I am trying to integrate bbPress with WordPress, and the only thing in my way (for now) is the sidebar. How do I disable sidebar in bbPress? I know that one way is to manually remove or comment out `<?php get_sidebar)(); ?>` in all bbPress template files. But I would like to know if there a way that will allow me to quickly allow me to turn it on or off — like adding some code in functions.php etc. Thanks.
Okay, I manually commented out all instances of `<?php get_sidebar)(); ?>` in bbPress templates like so: <?php //get_sidebar)(); ?> Alternatively, you can simply remove the code as well. But I consider it a bad idea, in case you want to have sidebar in the future.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "bbpress, forum" }
Using AJAX in wordpress theme all In my theme there is a notification at top. After user login he can see the notification update. when click on notification i want to make change in database alert field value 0 to 1. My ajax call in theme $("#notifications-button").click(function() { $.ajax({ type : 'POST', url: " data:{action:'MyAjaxFunction'}, success : function(data){ $('.message-count').hide(); }, }); }); and in function.php file add_action('wp_ajax_MyAjaxFunction','MyAjaxFunction'); function MyAjaxFunction() { global $wpdb; echo (int)$user_ID; $wpdb->update( $wpdb->wp_frm_items, array( 'alerts' => 1) ); } but it not make any changes in alert fields in db. is that right way to call theme function using ajax?
You need to add the `$where` parameter to your update statement because it doesn't know which row to update. The `$wpdb->update()` method has no default value for the `$where` argument so you must supply one. < Try this: $wpdb->update( $wpdb->wp_frm_items, array( 'alerts' => 1), array( 'user' => get_current_user_id() ) );
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "theme development, ajax" }
How to set a conditional statement for $attachment->post_excerpt, to check for value? I have a custom function which looks if an attachement has a certain caption value, if so the attachement is selected, like so foreach ($attachments as $attachment) { if ($attachment->post_excerpt == 'single-gallery') { But how can i give a attachement two or more values and select one? So if i give an attachement the caption values of single-gallery | downloads it will be selected for single gallery and downloads Any suggestions?
You should not misuse the caption for such values. Just add separate fields for those data. There are also plugins for media tags which may fit better to your needs.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "attachments" }
How to let users choose where to search for posts? I have no code to let you correct/see, I'm still in 'thinking stage'. What i would like to achieve is this: A real estate website with a few search functionalities. This new agency (REALLY NEW we have no office actually!) will split the city in 4 (or more) parts, in each one of these part there will be different houses, each house will have different number of rooms or will be available only to girs/boys. So the user when reach my website have to be able to choose: Search Form 1 * Which Part of the city * Accept boy/girls/both * Budget Search Form 2 * Accept boy/girls/both * Budget * Which part And so on... Maybe the best way to have a simpler search query would be to use Custom Field, Am I wrong? Is there anyone who can help me to find a tutorial, or can point me to the right direction or has/know a plugin to do something similar?
I solved my problems using this simple plugin: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "custom post types, custom field, search, meta query" }
How to add just one page in Arabic Hi I have a WordPress site where all the content is in English, however I need just one page to be in Arabic with left to right text, plus some bullets which obviously appear on the right instead of on the left, how do I go about creating such a page?
@toscho is right about the direction of the text... But as someone who builds websites in hebrew all the time i would reccomend you create a custom page template by putting this tag in a copy of page.php /* Template name: arabic page */ THen you can design it differently... maybe remove the sidebar which is probably in english maybe make the structure different... you can even make the design a little bit different by loading additional css.. in that page you should use @toscho advice but i would implant the dir="rtl" command directly into that page so you would have better control.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 3, "tags": "multi language" }
Muliple featured images (or just images) per post Is there a way to have multiple "featured" images (or just images) per post...I mean without putting it into the regular text editor. I would like to have some control where the images go...hence make it work the way the featured image works (i.e. a separate meta box)
Take a look at this Q.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post thumbnails" }
How can I dynamically generate an image with a static image URL? What I'm trying to do is very simple. Whenever someone visits, say `site.com/socialproof.png`, I want it to use a rewrite rule to point it to a file in my plugins folder. Can I do this with WP's rewrite rules or do I need to manually add it to the `.htaccess` file? What would I use as the rewrite rule to do this? Thanks!
Using .htaccess rewrites wouldn't be a good approach since it would fail when the plugin is disabled. You also can't rewrite image URLs with WordPress because its native request parsing does not recognize single file names. However, if an image doesn't exist, the web server will redirect the request over to WordPress for handling. This allows us to hook in and include your dynamic image template. add_action('init', 'wpse_44612_init', 0); function wpse_44612_init(){ if(preg_match('/socialproof\.png/', $_SERVER['REQUEST_URI'])){ require_once(ABSPATH.'/wp-content/plugins/SocialProof/classes/SocialProofMakeImage.php'); die(); } } With this approach, your URL appears as a static image, but is dynamically generated via your PHP class file. You can download the plugin file is here.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "url rewriting, htaccess" }
Added a new template file to a theme - get Call to undefined function error I added a new file in the theme folder and it doesn't seem to be working properly. The first line `get_header();` creates an error `Fatal error: Call to undefined function get_header()` like it's not seeing any includes. Any ideas why that happens? All files in the same theme folder work just fine except this one.
You are prbebaly using wordpress elements outside the loop and since its a file ou dont access directly from wordpress structure but a file you created yourself you should include <?php require_once("../../../wp-load.php"); ?> Above the doc type opening tag in sendEMail.php file..
stackexchange-wordpress
{ "answer_score": -1, "question_score": 2, "tags": "themes, templates" }
Contact Form 7 - process form using a PHP script, instead of mailing I want to use a form from the `Contact Form 7` plugin to allow the users to upload a document to my website. The problem is that I'd like to manage those uploads from WordPress instead of receiving them in my E-Mail. Is there a way of redirecting the output of those forms to a PHP script, or something similar?
Take a look at the `wpcf7_before_send_mail` hook CF7 provides. add_action("wpcf7_before_send_mail", "wpcf7_do_something_else_with_the_data"); function wpcf7_do_something_else_with_the_data(&$wpcf7_data) { // Everything you should need is in this variable var_dump($wpcf7_data); // I can skip sending the mail if I want to... $wpcf7_data->skip_mail = true; }
stackexchange-wordpress
{ "answer_score": 7, "question_score": 5, "tags": "uploads, plugin contact form 7" }
In the Wordpress admin, how can I find out which page (themes.php, widgets.php, etc.) I'm on? In the Wordpress admin, how can I programmatically find out which page (`themes.php`, `widgets.php`, etc.) I'm on?
You can determine that with wordpress' `get_current_screen()` function. It will not return just a page name though, it will give you an object containing a bunch of different data on what screen you're on.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "wp admin" }
Strange permalink issue: can't rename /company-2/ to /company/ I created a page titled company. But the permalink turned it into /company-2/, trying to change it to just /company/ doesn't work. The website just has 8 pages and none is called company (don't know if company as page title is used in the past?). What can i do and what is the cause? Where should i look? Not afraid to use phpmyadmin ;) regards
Check the slugs of the other pages - chances are /company/ is being used for one of those. You could also go to /company/ on your site and see if anything pulls up. As mentioned in a comment, make sure to check the trash as well. You may have deleted a page with that name, but if it is still in the trash you can not reuse the name.
stackexchange-wordpress
{ "answer_score": 11, "question_score": 17, "tags": "permalinks" }
Wordpress home page showing 404 error I've had a look for anyone experiencing the same issue but to no avail. I am currently working on a Wordpress site that previously did not have permalinks, so have added these (i.e. to change the URLS from ?p=123 to /about/the-company etc.) in the standard way but I've ended up with the homepage displaying a 404 error. All of the other pages work fine bar the home page. I have since tried deactivating it though now end up with the error still occurring. It seems to be a bit temperamental; in some browsers it works but others it doesn't. The issue can be seen at: < Thanks in advance!
Try checking what your front page is set to in Settings > Reading. It should either have the **your latest posts** option selected, or the **static page** option selected and the front page set to a valid page. **Edit:** Wait... the < url you provided doesn't exist! Maybe you mean <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "permalinks, mod rewrite, linux" }
Exclude the category in Wordpress ## My question: This code retrieves the categories. I need to exclude the category number:81. Is there an easy way to exclude it in this code? <?php $cat_lists = retrieve_cat_data_sp( get_option('bn_exclude_home_lists') ); for ($i = 1; $i < count($cat_lists); $i++ ) { if( (get_category( $cat_lists[$i] )->count) > 0 ): ?>
If retrieve_cat_data_sp is the function from this question then that returns categories except the ones given in the argument: $cat_lists = retrieve_cat_data_sp('81'); It essentially a wrapper for `get_categories`. So to exclude multiple Ids $cat_lists = retrieve_cat_data_sp('81,82'); If you want to exclude 81 as well as those IDs listed in `get_option('bn_exclude_home_lists')` then, assuming that option returns something in the form of comma separated IDs `'12,13,36'`: $exclude = (get_option('bn_exclude_home_lists') ? get_option('bn_exclude_home_lists'):''); $exclude .=',81'; $cat_lists = retrieve_cat_data_sp($exclude);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, exclude" }
How to make pages that arent indexed for ajax applications I'm using a content section on my homepage to switch through multiple loops with ajax tabs and to do that a tutorial told me to make multiple pages and assign each page with a different template which contains the loop I want to display. But by doing that I'm creating top level pages that display loops on a blank page without styling. That makes me think they will get indexed and I'll have the unstyled pages showing up in searches. What's the right way to do this?
You can use the constant DOING_AJAX to check if a current request is AJAX or not. This would let you do something like this in your templates: if ( DOING_AJAX ) { //show your content } else { //return 404 error global $wp_query; $wp_query->set_404(); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "ajax, page template" }
Retrieving custom field array value through db query I'm trying to query the database for posts based on multiple custom fields. This is easy enough with the code below if values are simple: $querydetails = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'field' AND wpostmeta.meta_value = 'value' AND wposts.post_status = 'publish' "; But how do I query a value that is stored in array form, like a:1:{i:0;s:8:"value";} ?
You can't query the database for a value in the array. However you can grab the entire array and parse the array to get your value. Check out PHP ARRAY-VALUES. More than likely you'll need to use a for each statement. Does the value your trying to get appear in the same spot in the array? If so it should be easier to target. Good Luck!
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "query, wpdb" }
How to create custom post listing in the admin? I want the defult CPT listing to include not all posts but only some, according to a specific taxonomy. is there a way to do that ?
This trick should help you... <?php add_action('pre_get_posts', 'filter_posts_list'); function filter_posts_list($query) { //$pagenow holds the name of the current page being viewed global $pagenow; $post_type = $query->get('post_type'); //Check the post type and whether its the list page, then set the taxonomy if($post_type == 'my_cpt' && 'edit.php' == $pagenow) { //global $query's set() method for setting the taxonomy $query->set('my_taxonomy', 'my_taxonomy_value'); } } ?> You can use any WP_Query parameters with the `set` method to modify this solution. For a detailed explanation, hit this.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "custom post types, listing" }
TinyMCE Advanced newline problem I am using TinyMCE Advanced plugin according to qTranslate in a wordpress 3.3 installation. **My question is:** why does tinymce translate visual editor new line ("enter" key) in a `<p>&nbsp;</p>` instead of `<br/>`? Is it possible to change this behavior?
Go into Settings -> TinyMCE Advanced, and check the option `Stop removing the <p> and <br /> tags when saving and show them in the HTML editor`. This will allow you full control over those tags inside the HTML view. For a single line break without overriding the editor, use `Shift+Enter`. To override the editor and make `Enter` a single line break, put this into your `functions.php`: function change_mce_options($init){ $init["forced_root_block"] = false; $init["force_br_newlines"] = true; $init["force_p_newlines"] = false; $init["convert_newlines_to_brs"] = true; return $init; } add_filter('tiny_mce_before_init','change_mce_options'); This does not convert `shift+enter` into `<p></p>` however, and this will cause some strange behavior for already existing content (if you're inside an existing `<p>` it will give two lines instead of one), so I would strongly recommend getting used to `shift+enter` instead.
stackexchange-wordpress
{ "answer_score": 10, "question_score": 6, "tags": "plugins, tinymce, plugin tinymce" }
Wordpress admin for a custom post, hide/collapse the main "title" and "description" boxes Is there a way to hide the main "title" and "description" boxes for a custom post? I have a custom post with a large meta box. I won't be using the regular title and description so I would like to either hide it or collapse it so the user won't have to scroll to get down to my meta box.
When you register the CPT, you register it with `supports`. If you do not include `title` and `editor` in this array wordpress will not display the main title or the TinyMCE editor.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, admin" }
Typical wp_kses $allowed I have a custom post textbox that I want to sanitize using `wp_kses` before I update my post meta. I was looking for examples of common `$allowed` settings, but I have only seen this example: $allowed = array( 'a' => array( // on allow a tags 'href' => array() // and those anchors can only have href attribute ) ); What is a typical `wp_kses` `$allowed` setting? Can someone provide an example of what they normally filter for?
I would disagree with the solution posted by @JaredCobb, `wp_kses()` is much more flexible than the method he presented. It can strip out unwanted attributes from tags without destroying the tags themselves. For example, if the user put in `<strong class='foo'>`, `wp_kses()` would return `<strong>` if you did not allow class, whereas `strip_tags()` would remove the `<strong>` completely. @redconservatory: The attributes you'll want to use are as follows: $args = array( //formatting 'strong' => array(), 'em' => array(), 'b' => array(), 'i' => array(), //links 'a' => array( 'href' => array() ) ); This will allow bold and italics with no attributes, as well as anchor tags with an `href` attributes...and nothing else. It uses the whitelisting principle, which @jaredcobb rightly noted is the better way to go here.
stackexchange-wordpress
{ "answer_score": 9, "question_score": 14, "tags": "wp kses" }
Page only shows when user is logged in (even with visibility set to public) I'm trying to troubleshoot an issue on a client's site. There is one specific page which appears as "not found" unless you log in and then visit the front end, in which case it appears normally. The visibility on the page is set to public, and in every other way it's a normal boring wordpress page. Stranger still, it only started happening recently (after months of trouble-free use). Problem page: < Any ideas why this would happen?
Try to reset your permalinks. If that doesn't work I'd make sure their isn't another page named schedule in the root directory. It's possible there is an older (deleted page or post) with the same name stuck in the database as well. I've experienced this when I deleted a page or post and then created a new one with the same name. Check the wp-posts table for a conflict. Good Luck!
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "admin, pages, permissions" }
Add 1 category more to If_in_category statement **Hey everyone, a simple question.** # Question I need to add one more category: Events in the if statement along with News which is stated in the code. How can I add it? _**Thank You very much :)**_ # Code <?php if (in_category('News')) : ?>
This is the answer :) <?php if (in_category(array('News', 'Events'))) : ?>
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, templates" }
Instructions for a custom post type Is there any way to put some instructions for a custom post type inside the post admin at the top of the add/edit page? I know you can put the instructions inside of a meta box, but at the top would be easier for the user to read....
You should be able to add help tabs with `add_help_tab()`. You'll need to filter which page you add it to based on the data returned by `get_current_screen()`, but that's simple.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "admin" }
I'm getting a '500 Internal Server Error' when I try adding menu items For some reason, I suddenly get `500 Internal Server Error` when I try to add menu item to a menu and I can't figure out why. I'm running Apache2 with Centos 6 OS on a VPS. I have PHP 5.8 and MySQL 5.1 This is the error message: > Internal Server Error > > The server encountered an internal error or misconfiguration and was unable to complete your request. (...) * My error_log file shows nothing. * I can create new menus * I can not add pages or custom links to menu items * I've deleted the .htacess file and get the same error * I can add new pages and posts Can anyone help me to figure out what may cause this weird problem?
I found this message from Mark Jaquith, WP lead developer: > The WordPress core team is quite aware of this issue, and it is absolutely something that needs to be solved. It is an issue with how the menus are saved. Too much data is passed back. It takes a lot of memory and computation time, and many servers are configured to have limits on the number of vars you can POST in one request. Unfortunately, we just couldn't reach a consensus on the best way to solve it in time for WordPress 3.2. So for this release, it will have to remain a known issue that menu saving performance degrades or generates errors beyond a certain point (which may vary from server to server). > > The Trac ticket has been tagged as 3.3-early, which means we'll put it as high priority early in the 3.3 development cycle. > > I appreciate your feedback and for holding us to a high standard! This is how things get better. The question is, when will t his be fixed? :-/
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "internal server error" }
Functions.php and includes My functions.php file is getting on the long side. Is it all right to use includes to break it up (php includes I mean) or is this considered bad form?
Many theme frameworks and complex themes break up functions into different files and include them in one file called functions.php, sometimes within a folder called `inc`. If it's your own theme, you can pretty much do what you want. If it's a theme to be released, end users typically look for a functions.php file as the default WP framework functions file. The two latest default WP themes - twentyten < and twentyeleven < \- use one functions.php file, as that's part of the standard WP theme file structure. But again, many themes use multiple files for functions, and if a user wants to work with or modify the theme, they will need a certain level of proficiency anyway. Code comments are helpful.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php" }
Condition display metabox in case the post is saved I need to register a metabox in my WordPress custom post, but only in case the post is permanent saved in database. What I mean, when the user click on "Add new" I don't want to display the metabox. When the user click on "Publish" after the page refresh display the metabox. The post status doesn't matter (published, private or what ever) Any idea ?
As an alternative to @m0r7if3r's solution, the `add_meta_boxes` hook optionally passes two variables, the post type and post object. You can use this to conditionally add your metabox. New posts have the post status of 'auto-draft'. add_action( 'add_meta_boxes', 'myplugin_add_custom_box',10,2); function myplugin_add_custom_box($post_type, $post) { if($post->post_status != 'auto-draft'){ add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'post' ); } }
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "metabox, conditional content, publish" }
How do you create a custom WPTouch theme? I have WPTouch Pro installed and it does a great job at device detection as well as handling most blog posts. However, I want to make a mobile version of a homepage that doesn't have any blog posts. I know you can edit the css for a theme by making a child theme and editing it. Is this the preferred method to get WPTouch to show more content from the original page? That link is here: < Also, someone is using shortcodes; not sure if this works for content that WPTouch is already ignoring: < Thanks in advance!
You can write a Child Theme as for any other theme. This way you can * extend the functionality * override stuff that's wrapped inside a `if ( ! function_exists('function_name') )` statement in the parent themes functions.php * override templates There should be no real difference between such themes and normal themes.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 2, "tags": "themes, css, plugin wptouch" }
How to hide 'Home' button from appearing on supages - twenty eleven theme How could I make it so the ' _Home_ ' button / text link doesn't appear in the top menu as the user navigates to a subpage?? _(So the menu stays the same accross)_
I usually use a custom menu, which lets me take move any menu item around that I want. Twenty Eleven does support a custom menu in the primary navigation area, so perhaps that would be your quickest solution.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 0, "tags": "navigation, theme twenty eleven" }
Edit custom taxonomy description programatically I've added a custom taxonomy and I wanted to know if there is a way to edit a custom taxonomy's description. Here's the description field. !image of custom taxonomy IS there a function that provides access to this field? And if so, would I be able to use it in the New Posts page?
If you `get_term()` you can access the description via the `description` property. To update a term you can use `wp_update_term()`.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom taxonomy, taxonomy" }
How important is it to enqueue a theme's stylesheet? I have trawled the net looking for an answer to this, but for some reason all I can find are actual examples, but without that particular explanation, which is clear say in the case of scripts. Can someone explain to me why it's important/advantageous to enqueue styles when developing a theme, rather than just using `<link rel=stylesheet>` in header.php. Also, what about the theme's default stylesheet, should that be enqueued too?
It's important to enqueue the stylesheet because it will allow child themes the flexibility of dequeueing it as well as allowing it to be listed for dependencies and a multitude of other things. It just generally allows greater flexibility, both for you and for any other developers who interact with your code. It's also important to note that using the default stylesheet in your theme is not a requirement. The stylesheet must be PRESENT, but if you use it for nothing more than to name your theme, set the version, etc, wordpress is COMPLETELY fine with that, as are the people who approve themes for the main repository.
stackexchange-wordpress
{ "answer_score": 17, "question_score": 20, "tags": "theme development, css, wp enqueue style" }
How to mark every 3rd post I'm working on a WordPress site for my band and I'd like to mark every 3rd post on our blog page to have a special class applied to it, anybody have any pointers on how to achieve this? Any help is very very appreciated, thanks! rock n roll.
My approach. No extra function, no filter. :) <?php $GLOBALS['wpdb']->current_post = 0; ?> <div <?php post_class( 0 === ++$GLOBALS['wpdb']->current_post % 3 ? 'third' : '' ); ?>> Alternative: <div <?php post_class( 0 === ++$GLOBALS['wpdb']->wpse_post_counter % 3 ? 'third' : '' ); ?>>
stackexchange-wordpress
{ "answer_score": 15, "question_score": 17, "tags": "posts, count, post class" }
How can I print out a single stylesheet or javascript link? I know I can use `enqueue_script` and `enqueue_style` to register scripts and stylesheets, however I'm trying to print out just the link to the adminbar css: <link rel='stylesheet' id='admin-bar-css' \ href=' type='text/css' media='all' /> I could just include that text on my page but I was hoping for something like wp_print_script('admin-bar-css') Is there such a thing?
to print a single style: wp_print_styles('admin-bar'); to print a single script: wp_print_scripts('admin-bar'); note that the handle must be registered first using wp_register_style() or wp_register_script(). <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, themes, wp enqueue script, wp enqueue style" }
Last Update time in widget I have a widget which can be updated every time with few values and admin update it on daily basis now how to get its last update time.
When you save the widget, you can save a field (which won't be setable in the admin interface) which stores the current time and then use that when you go to do the widget output.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "widgets, updates" }
Is it possible to not receive email notifications for comments? I created several blogs. Two are sites I maintain but others are sites I created for other people and I retain administration access to them just in case they need me to go and fix some page, but I don't want to receive notifications every time they have a new comment waiting for moderation. Is there a way in WordPress that while being an administrator of a blog, to not receive the email notifications for some blogs and still get them for some other blogs?
This is a one time work for every blog you maintain. Go to Dashboard >Settings >Discussion and see following: E-mail me whenever: * Anyone posts a comment * A comment is held for moderation * Someone likes one of my posts * Someone follows my blog Unmark the option at which you don't want to recieve any email notifications. All done!
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "email, notifications" }
Is there a plugin for posting inline comments, like in MS Word? I want to make a cookbook style wordpress website, on which visitors can place comments inline. Like you do in a paper book with a pen: between the lines. Or like how MS Word handles comments. Does anyone know a plugin that makes this possible? I've searched and searched, but all I found was this and it was of no use: < I don't get it to work and the developers page is nothing more than a logo.
There is a plugin with that readers can post comments inline, like in Microsoft Word. The WordPress plugin bases on inlineDisqussions by Tsi and is called Inline Comments: < Inline Comments adds the great Disqus Comment System to the side of paragraphs and other specific sections (like headlines and images) of your post.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 6, "tags": "plugins, comments" }
Trending Topics Plugin I am looking for a trending topics plugin as displayed on techcrunch. I have searched alot to find the vertical displaying plugin. If anyone could help out, I would be very thankful. ## EDIT: Here is a visual image of how it should look like. !enter image description here
If by hot trends you mean the categories, you can list the categories with the most posts using this plugin: < **Some styling work will be needed, but that is _unavoidable_ no matter what plugin is used.** Tech Crunch however uses tags not categories, so instead you can use this: <
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins" }
Which wordpress theme is compatible Optima Express theme (real estate inventory) plugin? I am using Optima Express theme (real estate inventory) plugin for my wordpress website. And it is working perfect in admin are. But as i started to use it in front end it is started to conflict with Jquery of current active theme. It does work with Twenty-Eleven, Twenty-Twelve but not the "Striking" and "Karma"themes I wish to use with this plugin. What should i do ? Should i go to everyplace in code and write JquerynoConflict OR any better solution for this ? All suggestion will be welcome.
From the looks of it, the IDX plugin is coded properly with noconflict, but there is some inline JS in the themes that is not. Wrapping those functions in (function($) { // your functions here })(jQuery); will take care of the problem. All JS in WordPress should be run in noconflict mode, so yes you'll need to go through the theme code and make sure it's functioning properly.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, themes" }
cross-host benchmarking with wordpress I am doing some cross-host benchmarking with wordpress, and rather than going to the huge trouble of setting up an identical install of wordpress on each host, a huge investment of time, etc., I want to create a single php file that would simulate the php demands of wordpress and use that file to gauge each host's relative wordpress efficiency. What might such a file look like? Or does it matter? Would a standard php benchmark file suffice? Note: for my purposes, I'm ignoring database calls from my calculations.
Afaik there's no real performance test available (what exactly do you want to check?), but you can find a plugin that came out of the first Q below, that might help you doing some profilling. * * * An interesting read might be… 1. refactoring WP to improve memory performance 2. generally a lot of Qs inside the performance tag * * * Also: You can use the Debug Bar Plugin: ![]( (source: wordpress.org) * * * …or if it's about plugin performance, try to take a look via the P3 Plugin Performance Profiler Plugin. No need to run this on multiple sites, as it meassures in %-values. ![](
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "performance, hosting" }
Add a meta box to ALL Pages I'd like to add a meta box to all my pages (not posts) but it looks like I am only able to add it for a specific post based on the codex? add_meta_box( $id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args = null );
Try this. This is part of some code I use. // Add meta boxes to Page add_meta_box( 'RelatedImage', __('Related images'), 'related_images_meta_box', 'page', 'normal', 'high' ); function related_images_meta_box($object) { $nonce = wp_create_nonce(plugin_basename( __FILE__ )); ?> <input type="hidden" name="wp_filebrowser_nonce" id="wp_filebrowser_nonce" value="<?php echo $nonce; ?>" /> <table> <tr> <td> <label for="related_image" class="">Related image</label> </td> <td> <input type="text" id="related_image" name="related_image" value="<?php echo 'your meta property' ?>" size="40" /> <td> </tr> </table> <?php }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "metabox" }
How do i manually place a widget code Is there a way that i can place a certain widget anywhere on the site? **For example** : I'm using the text widget in my sidebar, for the title I put YouTube, and I placed the YouTube embed code in it. But I want that widget to go at the top of the site. How do I make this possible, while still using the widgets menu, but not show up in the sidebar, but wherever I place it? If it's not possible, does anyone know of a YouTube sidebar widget, one that can let you place the widget code anywhere on the site and also do it from the widgets menu?
Just register another widget area. Don’t take the name _sidebar_ literally, you can use the fields anywhere on your page. In your theme’s `functions.php`: add_action( 'after_setup_theme', 'register_multiple_widget_areas' ); function register_multiple_widget_areas() { register_sidebar( array( 'name' => 'Sidebar', 'id' => 'sidebar', 'description' => 'describe the function of the box.' ) ); register_sidebar( array( 'name' => 'Header', 'id' => 'header-widget', 'description' => 'Goes at the top of the page.' ) ); } And wherever you need the header widget call: dynamic_sidebar( 'header-widget' ); See also `register_sidebar()` and `dynamic_sidebar()`.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 5, "tags": "widgets" }
Disable single post page Is there a way to disable single post page, for example when some tries to go to single post page to show 404 page.
Although I'm also curious as to why you'd want to do this, and would probably suggest using a custom post type instead, this would probably work (actually works for any single post type except pages and attachments): add_action( 'pre_get_posts', 'wpse44983_single_post_404' ); function wpse44983_single_post_404( $query ) { if ( $query->is_main_query() && $query->is_single() ) { $query->is_404 = true; } }
stackexchange-wordpress
{ "answer_score": 9, "question_score": 1, "tags": "posts, functions, single" }
Shortcode to display all the post from a category in a page I have 10 category, and when i select a category in the sidebar il list all the post from that category.... FINE, beautiful Now, i like a page, with some text and photos and then after that content, i like to have all the post from a category listed, just like the category view... Is there a plugin or a short code that just do that ?
Try this... <?php function list_post(){ //or you can use the cat id here, check the codex for WP_Query $q = new WP_Query(array('category_name' => '<cat slug here>')); if($q->have_posts()): while($q->have_posts()):the_post(); the_title(); endwhile; else: echo "No posts found!"; endif; wp_reset_postdata(); } add_shortcode('list_post', 'list_post'); ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, shortcode" }
What is the difference between esc_html and wp_filter_nohtml_kses? What is the exact difference between `esc_html` and `wp_filter_nohtml_kses`. Everywhere I look says that both strip **all** the html, the only difference I can see is to do with exactly how they do this. Does `esc_html` encode the tags and does `wp_filter_nohtml_kses` strip them altogether?
Contrary to what you have been looking at, `esc_html` does **not** strip all the HTML, it escapes it, meaning it encodes it into safe HTML entities that do not break HTML tags. `wp_filter_nohtml_kses` strips all the HTML. When in doubt **always** consult the source code. It is accessible online. `esc_attr` is short and sweet, uses `_wp_specialchars`, defined in _wp-includes/formatting.php_ `wp_filter_nohtml_kses` is defined in _wp-includes/kses.php_, and " _Strips all of the HTML in the content._ "
stackexchange-wordpress
{ "answer_score": 4, "question_score": 6, "tags": "plugin development, theme development, security, sanitization" }
How can I get a list of latest posts outside of my WP install? I have a site with WP installed at /blog, and I'd like to just get a list of the latest blog posts to display on the site home page... that is to say, my custom (PHP) home page, NOT a Wordpress page. I found this, but it doesn't work-- the latest version of Wordpress is looking for Translate_Entry.php or some other kind of class that it can't find. Is there an easy way to do this, short of picking up and parsing the RSS feed on the fly?
You have several options. ## XML-RPC < is the place to start. The API exposes a large number of methods to access WordPress data "outside" of the full WordPress context. Difficult to setup, connection requests overhead. ## wp-load.php Include `wp-load.php` to load up WordPress. You will need to `chdir()` into WordPress first for this to work properly, depending on your environments and contexts. Easy. chdir( 'wordpress' ); require( 'wp-load.php' ); foreach ( get_posts() as $post ) { echo "<h2>{$post->title}</h2>"; } This is very similar to the link you posted. The error you're getting is probably an include that is relative to some path. So change directories before and after. ## XML feeds Parsing the feed may be overkill, unless you cache maybe. Highly discouraged.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "posts" }
Featured Image Thumbnail Sizing ! The image on the left is what it is currently looking like. I used developer tools to change the width & height of all the image fields for the image on the right, however I would like some sort of cropping to get a similar effect without the scaling issues. My code is below. <div class="thumb"> <?php the_post_thumbnail(153, 115, true); ?> </div> .inner .thumb { width: 153px; height: 115px; overflow: hidden; }
I've approached this problem in a few different ways, here's some ideas: 1. Just grad the medium sized thumbnail with `the_post_thumbnail('medium');` (or any defined size that is bigger than what you want displayed), and apply a `.inner .thumb img {width: 153px; height: auto;}` css rule. If it's too tall it will get cropped from your `overflow:hidden;` on the container. This will cause css based image scaling, but maybe that's fine. 2. You could use `wp_get_attachment_image_src` to get an array with the image's height and width and use some mathematics with the ratio you want to resize or crop the image using php's image processing functions... this seems messy and overkill 3. Set your default thumbnail size in wordpress's media settings to 153x115 and use the proportional option. Like answer 1, this the excess will get cropped off by your container, you're just letting wordpress resize the image for you instead of css
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "post thumbnails, cropping" }
Conditional template tag for buddypress pages I'm trying to assign a special template only to buddypress pages (activity, members, profile...). All other posts / pages use a different template. Problem is: I just can't find a good way to tell if a page is "rendered" by buddypress or by the wp "core". I've looked in the bp codex and found the template tag bp_is_member() and others, but none for an overall approach. Are there hooks that I could use or other template tags that I didn't find? I'm not looking for a customization of the sidebar only, so conditional widget plugins won't do the job. Any help is appreciated Heiner
`bp_current_component()` does not necessarily return a boolean - it returns `false` if not in a BP component, but will return the name of the component otherwise, as a string. Internally, BP uses the function `bp_is_blog_page()` to do what you're asking - if it returns true, it's not a BP page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "templates, buddypress, template tags" }
Get user info outside Wordpress Not quite sure why this is happening, hopefully someone can help. I have a wordpress installation, lets say for arguments sake it's installed to < I have a file called test.php with the following code: <?php include '/php_path_to_blog/wp-blog-header.php'; echo get_current_user_id(); ?> Now the odd part is if i have a user logged in and place this file within my wordpress directory and call it by going to < it outputs the correct user id of the current logged in user. However if I move the file to the root directory of the site and call it by going to < it outputs 0 as if there were no user logged in. It seems that some functions work properly outside of the installation directory and some don't. I would like them to work outside the wordpress isntallation directory. Any help would be greatly appreciated.
Very similar to this question of a couple of hours ago: How can I get a list of latest posts outside of my WP install? Use `chdir()` to move into WordPress root before including and even calling anything related to WordPress. The are cases where relative directory and file references are used, thus breaking many things. You can return to the previous directory afterwards by storing the `get_cwd()` first. $cwd = get_cwd(); chdir( 'wordpress_root' ); include 'wp-load.php'; // ... do stuff with WordPress chdir( $cwd ); // ... continue happily ever after Additionally, seeing that you're working with session cookies, the paths for these cookies are invalid for the URI you're working from. The browser will not send the WordPress authentication cookies that you have acquired previously since the domain roots are invalid and outside of the WordPress scope. You will need to alter the roots of these cookies from WordPress with something like this <
stackexchange-wordpress
{ "answer_score": 3, "question_score": 1, "tags": "users, login, user registration" }
How do I get my nav menu to show sub pages? < is my website. I've got the top menu which is the one that was in the theme when I started to customize it. It's got a test drop down that works just fine. I included a secondary menu under the slider with this code <div id="secondaryMenu"> <?php $menuID = 'bottom-nav'; $footerNav = ''; if (function_exists('wp_nav_menu')) $footerNav = wp_nav_menu( array( 'theme_location' => 'footer-menu', 'container' => '', 'fallback_cb' => '', 'menu_id' => $menuID, 'menu_class' => 'bottom-nav', 'echo' => false, 'depth' => '2' ) ); if ($footerNav == '') show_page_menu($menuID); else echo($footerNav); ?> </div> It works just fine, except for the fact it does NOT show drop downs? I've got 3 pages underneath "Admissions" the furthest left item, and they don't show up?
First let me start by stating the @cale_b is probebaly right and you should first look at your css / jquery to ensure that your items arnt being hidden... Also - you should change this: 'depth' => '2' To this: 'depth' => 0 0 = show all & no need to surround it like this: '0' This is the right way 'depth' => 0 (since its not a string.) Hope this Helps, Cheers, Sagive.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "functions, jquery, javascript, sub menu, menus" }
Get the first post term How do I get only the first term of a custom post type. I can get all - no problem. This what I am using to grab all of them <?php foreach ($terms as $term) {echo '<a href="'.get_term_link($term->slug, 'sitecat').'">'.$term->name.'</a>,';} ?> >> <a href="<?php the_permalink(); ?>"><?php the_title('', ''); ?></a></h2></span> Would appreciate an answer using my code but any help is most welcomed
I'm not sure what you mean by 'first' taxonomy... but, $terms = get_the_terms( $post->ID, 'mytaxonomy' ); returns an array of taxonomy term objects, so $term = array_pop($terms); Would give you the first term in the array. And then: echo '<a href="'.get_term_link($term->slug, 'mytaxonomy').'">'.$term->name.'</a>,' _(You may want to include some if statements, in case an empty array or error is returned (see`is_wp_error`)_
stackexchange-wordpress
{ "answer_score": 30, "question_score": 11, "tags": "custom post types, categories, taxonomy" }
what is the cache directory for in my theme? (version control it?) I was wondering what processes exactly use the `cache` directory inside my theme's directory. More specifically, I am wondering if I should add any of those files to my git repo.
If you use someway "compilable" WordPress theme (are they exist?!) cache-dir _may contain_ theme-files, processed by some tools and prepared for using by httpd-server of site. As all and any artifacts, constructed from **versioned data** , these files can and have be excluded from versioning - **everybody** will be able to **rebuild** these files from _versioned source files_
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "cache, version control" }
How to disable Edit Post and Allow only Custom Field? What I would like to know is if it is possible to disable the edit post function in wordpress based on User's roles. I try to explain better. Let's take an 'Editor' as role example: I would like Editors, Authors.... but NOT ADMIN to be able to write posts only using Custom Fields instead of the 'classic' built in edit post function of WordPress. Is there anyone who knows how to do it (maybe it is only a sentence or 2 in functions.php) or who as/know a plugin that will let me do it? Thank you very much!
You can remove post type support for the editor on a conditional basis. The following should work: add_action( 'add_meta_boxes', 'wpse45113_remove_editor' ); function wpse45113_remove_editor() { // change the capability and post type to whatever is appropriate if ( ! current_user_can( 'install_plugins' ) ) remove_post_type_support( 'post', 'editor' ); } I'm using `add_meta_boxes` because it fires not too long before the editor is initialized, but there are a number of hooks that would also work. You can similarly only add the meta box with the custom fields for those users within the same if block.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "custom field, functions, user roles, post editor" }
Contact Form Security Building my own contact form in Wordpress. Any there any security steps I need to consider other than the typical email etc validation and maybe a captcha. I am not sending any data to the database.
You should use a nonce to protect yourself from CSRF attacks. Even though you're not sending anything to the database, I'd suggest using some of the built in data validation functions (there is even a `is_email` function for you to use!) to strip out any HTML from your email. `esc_html( striptags( $your_email_content ) )`, for instance. You could also throttle contact form submissions from a single IP to prevent someone from submitting the same thing many times. I don't know of any contact form plugins that do that, but the WordPress comment system show you an error page if you submit too many comments within a certain period of time.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "theme development, security, contact, sanitization" }
conditional statement for profile pages I'm using different headers for in my wordpress/buddypress setup and I need a conditional statement for member pages. So everything that comes after mysite.com/members/. How do I do that with something like is_page()?
Try this function `bp_is_members_component()`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "conditional tags, members" }
Engadget Like Featured Breaking Plugin I am looking for a Engadget like **featured breaking** plugin. I have searched myself but did not found any relevant results. I would be very thankful for the help. ## EDIT: Here is a visual image of how it should look like. !enter image description here Thanks in advance.
You can get a plugin that does this here: < Called recent posts, you can add the widget and change the Title to 'Featured Breaking' !enter image description here
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "plugins" }
phpBB 3 to bbPress I am updating a diabetes forum to make it more extensive for which I have previously used phpBB 3. I have decided to use WordPress on the new build and have installed bbPress, however, I would like to import/transfer the existing users, forums and posts on phpBB into bbPress. There aren't that many of each to do manually, but I would still like to be able to do this manually. I have tried the ForumConverter and WP phpBB Bridge plugins but neither of them worked, so if anybody has any advice or suggestions that would be greatly appreciated. I don't know if it's because I have downloaded the latest stable version of everything but strangely I don't appear to have any tables with the "bb_" prefix in my database either...
Never mind now. Fortunately (in this case) I have found an alternative solution to bbPress for WordPress - Simple:Press! I personally think that Simple:Press is much better not only because it allowed me to import everything from phpBB very easily but also because it seems much more comprehensive and well put together; - more comparable to phpBB! So, basically Simple:Press is my answer and in a strange kind way, I'm glad I ran into problems with bbPress!...
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "plugins, import, bbpress, migration" }