question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
Actually I have the problem that I provide a menu link (predefined in theme) to the latest post of a specific custom post type. I achieve this by the following function … <code> function get_latest_magazine_issue_url() { global $wpdb; $query = "SELECT ID FROM {$wpdb-&gt;prefix}posts WHERE post_type='magazine_issue' AND...
Oh, the comment on your question makes it clear. In case you would like to always return a fresh latest post, no matter the page with menu link gets or not refreshed must be solved in another way. At first: Create new page, let's say: "Latest post" - note it's ID. And than add this into your functions.php: <code> funct...
How to solve this without flushing the rewrite rules for each post query the visitor triggers?
wordpress
I have some code as plugin, which I call via AJAX from a page one the site. It gets two drop-down values and uses them in tax_query to fetch some posts. Question: why do drafts return amongst results by default? I need to uncomment <code> 'post_status' =&gt; 'publish' </code> to prevent this from happening. User is not...
The problem is explained in the quote you've mentioned: "Default value is 'publish', but if the user is logged in, 'private' is added. And if the query is run in an admin context , protected statuses are added too. By default protected statuses are 'future', 'draft' and 'pending'." Ajax call is always considered to be ...
why do drafts return as part of wp_query?
wordpress
Okay, I'm trying to get posts that have been published within the last x amount of time, options being 8, 24 or 72 hours. I have the variables being passed to my featureHandler.php via ajax, then returning the posts, here is how I'm doing it: <code> $vars = $_GET['vars']; $time = $vars[0]; $order = $vars[1]; if ($time ...
here is a shorter version that assumes the GET parameter ?time=[integer] (for example ?time=8) <code> add_filter('posts_where', 'filter_where', 11); function filter_where($where = '') { if(isset($_GET['time'])){ $time = $_GET['time']; $time=(int)$time; // only allow integers if(in_array($time,array(8,24,72))){ $where ....
Get Posts updated or published within the last x hours
wordpress
I thought this was going to be quick and easy, but naturally it's turning out to be more complicated. I'm writing a simple plugin that creates a custom post type "Ad", and then puts a random ad at the bottom of posts. So I've created my custom post type - that's easy. Then I created a few ads, and I want to put the fea...
<code> the_post_thumbnail </code> is echoing content. You need <code> get_the_post_thumbnail </code> instead. That is your problem. I believe you should be able to swap this: <code> $the_ad = the_post_thumbnail(); </code> , for this: <code> $the_ad = get_the_post_thumbnail(); </code>
filter the_content, custom post type, and wp_query
wordpress
WordPress implements a simple order functionality by default. What's the common method, to retrieve the <code> menu_order </code> for the current post or page?
If you have the post with an <code> $id </code> : <code> $thispost = get_post($id); $menu_order = $thispost-&gt;menu_order; </code> WordPress itself does not provide a function to get the <code> menu_order </code> , so you have to query the <code> post </code> -Object. If you are outside the loop, you can use the above...
Get current menu_order
wordpress
I need your help as I got some issue with <code> wp-signup.php </code> page which I try to resolve but I am not able to do it. Issue is as follows, I want to replace the text 'Get your own %s account in seconds' with 'Fields with an asterisk will be shown on your website for the world to see'. I know that i can do it b...
you can try these hooks: <code> // // remove label label[for=signupuser] and #signupuser on wp-signup.php with CSS // add_action('signup_header','my_signup'); function my_signup() { echo "&lt;style&gt;label[for=signupuser],#signupuser{display:none !important;}&lt;/style&gt;"; } // // edit text displayed on wp-signup.ph...
How to edit wp-signup.php content using plugin
wordpress
First post here so let me know if I'm doing something wrong. The company I work for uses a custom FancyBox Wordpress plugin that allows us to use fancy box on images easily. Basically, when you click on the image it expands to fill the center of the screen. Standard stuff, however we're having a problem. Since last wee...
The Problem is that you include jQuery 1.9, in which the jQuery.browser was removed. Look at your <code> functions.php </code> , you will find a line in there saying <code> wp_register_script </code> or <code> wp_enqueue_script </code> with the parameter 'jquery'. The URL you are loading jQuery from is ' http://ajax.go...
FancyBox JS stopped working on multiple sites. Custom plugin responsible. Urgent help needed
wordpress
I've got this theme where you can add posts of type "portfolio", and I want to be able to reorder them up. I've added a custom meta field called "position" and I've set already those values. All good. My question is: How can I modify the query to join the wp_postmeta table and order them by the "postion" value? This is...
Check WP_Query Order by Parameters <code> $args = array( 'post_type' =&gt; 'my_custom_post_type', 'meta_key' =&gt; 'age', 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'ASC', 'meta_query' =&gt; array( array( 'key' =&gt; 'age', 'value' =&gt; array(3, 4), 'compare' =&gt; 'IN', ) ) ); $query = new WP_Query($args); </cod...
Reordering content using a meta value
wordpress
Since upgrading Wordpress from 3.4.2 to 3.5, Wordpress Mobile Edition has not worked. I have left a support request on the plugin's support page, but have received no reply in 2 weeks. I might have to conclude the plugin author is no longer supporting this plugin. I know this question might breach guidelines, but is th...
The plugin you are using hasn't been updated in 2 years. Check out the Jetpack for WordPress plugin . It comes with MANY useful modules, one of which is the Mobile Theme module. Another plugin that comes to mind is WPtouch , which is available in basic and pro ($$) builds.
Wordpress Mobile Edition not working with WP v3.5
wordpress
An Author 'XYZ' is need to be set as the Default author of all New Posts . Irrespective of the actual Author posting the content, the post should be saved by this author 'XYZ'. Is there a Plugin or custom functions, which serves this purpose? <code> Note : The existing posts should stay as it is, no 'change of author' ...
<code> function wp84782_replace_author( $post_ID ) { $my_post = array(); $my_post['ID'] = $post_ID; $my_post['post_author'] = 1 ; //This is the ID number of whatever author you want to assign // Update the post into the database wp_update_post( $my_post ); } add_action( 'publish_post', 'wp84782_replace_author' ); </cod...
Set a User as Author of all 'New Posts' posted
wordpress
I would like to create color scheme for my custom template that can be changed inside my admin panel . According to this thread it can "easily" be done. Author quotes: "create your color styles in seperate style sheets and name them like so. blue.css - black.css - brown.css - ect.... Then in your admin options panel yo...
Here is the answer to my question... Add this to your functions.php <code> // Options Page Functions function themeoptions_admin_menu() { // here's where we add our theme options page link to the dashboard sidebar add_theme_page("Theme Color", "Theme Color", 'edit_themes', basename(__FILE__), 'themeoptions_page'); } fu...
How to create color scheme for my custom theme?
wordpress
Does wordpress code base use mysqli or PDO? I know PDO is superior to mysqli but mysqli is not bad neither. Plus from one of the features of what makes PDO is superior to mysqli ( that is being database agnostic ) does not mean much to WordPress as WordPress will always use mysql server. But binding params with data ty...
WordPress uses <code> mysql_* </code> functions . http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/wp-db.php It has used those ever since I can remember, which probably answers your last question. It is what I would consider legacy code. I suspect it will be updated sometime soon (those functions were only...
WordPress mysqli and PDO
wordpress
I noticed in my home page's source code: <code> &lt;meta property="og:description" content="This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site vi...
That's a FaceBook plugin most likely using the output of the <code> post excerpt </code> - via <code> get_the_excerpt() </code> or whatever - to populate the <code> og:description </code> meta tag. It's placed there automatically by the plugin.
Where is this strange og:description coming from?
wordpress
I have a situation where it is needed that if I create two CPT pages wich both have the same name and the same slug. For example, if I add two CPT pages, wich both called "Post Name" : The first slug will be "post-name" , The second slug will be "post-name-2" . Because I added a custom part to the permalink structure w...
you might consider the 'wp_unique_post_slug' filter: <code> add_filter( 'wp_unique_post_slug','my_disable_unique_slug',11,6); function disable_unique_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ){ global $post; if($post-&gt;post_type=='cpt'){ // EDIT post type $slug=$original_slug; } r...
Don't change Custom Post Type slug to unique value
wordpress
How can I get the first category (linked to the category archive page) of a post excluding the category called 'featured'? I found various solutions but I can't combine them properly. Thanks UPDATE: This is what I ended up using: <code> $category = get_the_category(); $cat_id = get_cat_ID( $name ); $link = get_category...
Within the post loop you can do, <code> $category = get_the_category(); if($category[0]-&gt;cat_name == "featured") { //if first category in array is "featured", get next category in line $name = $category[1]-&gt;cat_name; $cat_id = get_cat_ID( $name ); $link = get_category_link( $cat_id ); echo '&lt;a href="'. esc_url...
Get first category only and excluding one
wordpress
I have a (relatively) tricky situation where my code requires changing the loop output every three posts, and within those three posts there are divs around two of the posts. The code below displays 6 posts and I would want to loop though a total of 24 posts, repeating this four times. Can anyone help? Thanks! FIRST TH...
You can do this with much less code, using the <code> modulo </code> operator. The modulo sign in PHP is <code> % </code> , and works like this: it gives you the remainder of a division, for example <code> 5 % 2 = 1 9 % 3 = 0 11 % 7 = 4 </code> So your code would look like this (I think you have a typo in your question...
Alternate loop output every three posts (within the same original loop)
wordpress
Using WP 3.5.0, Wordpress galleries have been working fine. I use the Cleaner Gallery plugin and Lightbox to display galleries in lightbox mode. Now I am using WP 3.5.1, a gallery I created on this page is output with inconsistant hyperlinks on the thumbnails. Some point to a URL with format: http://test.incredibleconc...
It looks like you have the gallery settings pointing to the attachment pages instead of the media files directly. You can try this shortcode <code> [gallery size="full" link="file"] </code> instead of the default <code> [gallery] </code> if you want different sizes, you can change the size parameter to size="thumb", si...
Wordpress Gallery not being output correctly/consistently
wordpress
I have been trying to output content of all post-types (Posts, Pages and CPTs) based on a term of a custom taxonomy that they must share (meaning if they don't share that particular term, the output should not include that post-type). Here is what I have so far: <code> $term_list = wp_get_post_terms($post-&gt;ID, 'pers...
we meet here again :) Try using this: <code> $term_list = wp_get_post_terms( $post-&gt;ID, 'persons', array( 'fields' =&gt; 'ids' ) ); </code> and <code> 'tax_query' =&gt; array( array( 'taxonomy' =&gt; 'persons', 'field' =&gt; 'id', 'terms' =&gt; $term_list ) ), </code> AFAIK, the <code> tax_query </code> accepts fiel...
How to output content based on same custom taxonomy?
wordpress
I have install the plugin Simple fields for WordPress, create an repeatable field for file. Upload an amount of images to an portfolio item. Now I will show these images on the page. I use currently the following code: <code> $file_id = simple_fields_value('image_repeater'); $image_info = wp_get_attachment_image_src($f...
For repeatable fields you can use the function simple_fields_values to get an array with all the field values. You can then loop through the array and do whatever you want with the values (in this case the images). See more info here: http://simple-fields.com/documentation/api/getting-values/simple_fields_values/
Simple fields plugin WordPress show repeatable file field
wordpress
I'm trying to modify the email that's sent to users when they are invited to join my multisite network. Understanding I can only use the pluggable function, how do I override the default email with a must use plugin? Right now it's not allowing me to override and shows the default text. Here's my current code: <code> i...
That function isn't for MS signups, the <code> wpmu_signup_user_notification </code> function in <code> wp-includes/ms-functions.php </code> handles that. here's the docblock from that function: <code> /** * Notify user of signup success. * * This is the notification function used when no new site has * been requested....
Not able to override pluggable function with a mu_plugin
wordpress
I have in my blog around 2k+ posts in 15 categories and around 1k tags. The problem now is that the website I bought the theme from decided to upgrade/update their themes infrastructure and now I need to export my normal posts into a custom post type. Ill explain below. To be able to use their portofolio grid template ...
I'd recommend pTypeConverter instead of Post Type Switcher. I've run into a couple of odd issues when using it. http://wordpress.org/extend/plugins/ptypeconverter/
Custom post types problem
wordpress
If you have an <code> index.php </code> with a loop such as: <code> if(have_posts()){ while(have_posts()){ the_post(); } } </code> And nothing is returned, you would generally do a: <code> if(have_posts()){ while(have_posts()){ the_post(); } }else{ //display message } </code> However, what if you have a <code> 404.php ...
If you want to force the <code> 404.php </code> template to load if there are no found posts, use the <code> template_include </code> filter: <code> function wpa84794_template_check( $template ) { global $wp_query; if ( 0 == $wp_query-&gt;found_posts ){ $template = locate_template( array( '404.php', $template ), false ...
Is the 404 page automatically displayed if a loop returns nothing?
wordpress
I'm trying to query all posts by an author and paginate them on the author.php page. I've tried messing with the WP default blogs per page settings and that doesn't help. I've looked at other posts on here and could find a solution either. This works on my category pages and custom template pages (with the exception of...
There is already a query on that page. <code> author.php </code> is an optional template file that, if present, WordPress will use for author archives. You shouldn't have to create another query on that page. I think that your query and the native query are colliding, at least in part because both queries will be using...
Pagination 404 errors for author posts query on author.php
wordpress
I have multiple JavaScript files that I want to load. Some of them in my <code> header.ph </code> p and the rest in the <code> footer.php </code> . These are the files: <code> &lt;?php &lt;script type="text/javascript src="/scripts/jquery-1.8.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript src="/scripts/c...
You can't have <code> &lt;script&gt; </code> elements within your PHP like that. Either take them out of the PHP delimiters ( <code> &lt;?php ?&gt; </code> ) or use <code> wp_register_script() </code> and <code> wp_enqueue_script() </code> to get your scripts within WordPress. Update how can i use wp_enqueue_script() w...
Add multiple JavaScript files to template header
wordpress
I'm wondering if there is any way to use get_template_part() with folders? My main folder has a lot of files now because I put every re-usable element in a separate file. I'd like to put them in folders then. There is no information about that in Codex: http://codex.wordpress.org/Function_Reference/get_template_part
In fact you can, I have a folder in my theme directory called <code> /partials/ </code> in in that folder I have files such as <code> latest-articles.php </code> , <code> latest-news.php </code> and <code> latest-statements.php </code> and I load these files using <code> get_template_part() </code> like: <code> get_tem...
Is there any way to use get_template_part() with folders?
wordpress
I have created a custom meta box for posts and I need to display said data. I have been using the below method to display the data, But I am in need of a slightly different solution. <code> &lt;a href="&lt;?php echo esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text4', true ) ); ?&gt;"&gt; &lt;img src="&lt;?php e...
You can try this: <code> &lt;?php // get image source: $metaboxtext3 = esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text3', true ) ); // get link: $metaboxtext4 = esc_attr( get_post_meta( get_the_ID(), 'my_meta_box_text4', true ) ); // check if the image source exists: if(strlen($metaboxtext3)&gt;0){ ?&gt; &lt;a...
Custom Meta Box If Else Statement
wordpress
When viewing my blog in the browser, the body tag (on the index page) has the following class: <code> &lt;body class="home"&gt; </code> On other pages (for this example, a page that pulls in posts that are within the category "project"), the body tag has even more classes: <code> &lt;body class="archive category catego...
The Function <code> get_body_class() </code> gives you an <code> Array </code> containing all the classes that are added to the body, so you can reuse them.
Reusing the page name class that Wordpress adds to body tag
wordpress
I have a custom post type and trying to set custom columns, the date column is there by default, and it appears right after the title. Do I have to unset the date first and then re-apply it, or is there a more elegant way of achieving this: <code> function custom_columns($columns) { unset( $columns['date'] ); $columns ...
That's the only thing there is to do: array manipulation . The filter <code> manage_edit-CPT_columns </code> is fired in <code> class-wp-list-table.php </code> : <code> add_filter( "manage_{$this-&gt;screen-&gt;id}_columns", array( &amp;$this, 'get_columns' ), 0 ); </code> Which in turn dispatches the function <code> g...
order of date column in custom post type
wordpress
It is possible to add subscript and superscript in a WordPress page title? I need to add pages with "H 2 O" in the title. I have been searching, but cannot find anything with answers... only a few non-answered threads on wordpress.org forums.
You can use markup in titles. <code> H&lt;sub&gt;2&lt;/sub&gt;O </code> will work just fine. I would use H₂O with a real <code> ₂ </code> because markup will be stripped in title attributes and in feeds. Note that WordPress will not create a pretty permalink for the correct character. The slug for my example will look ...
How to add subscript and superscript in WordPress page titles
wordpress
Lets assume following situation: I develop a plugin. The plugin requires custom database table to store some kind of information. From month to month I release new versions of my plugin. Different versions could have their own sets of changes of the table structure and table's data. For instance: version 1.0.0 has init...
Ok, to resolve these issues, let's implement the cascading upgrade process which will handle both use cases. First of all lets implement our plugin activation hook, which will be our entry point: <code> // define current plugin version define( 'WPSE8170_PLUGIN_VERSION', '2.0.0' ); // define our database table name defi...
What is the easiest way to implement cascading database upgrade for my plugin?
wordpress
The question is asked many times in different forms, but can't find my answer from any of 'em . Question is self explanatory, but need to mention some scenario: I'm not moving to <code> .org </code> , it's a personal domain, I've bought from somewhere else. I know how to export and import content from WP site. But if I...
" Moving to .org " means " moving from WordPress.com blog provider to your own installation of WordPress which you can download from wordpress.org " - just to clear out your first point. And than, after you export all data from your wordpress.com account, while importing them to your local install, you're asked to auto...
Moving WordPress.com site to personal domain intact
wordpress
Objective: Query and loop through a page's third-level "grandchildren" in a way that allows pagination. Here's the code that I'm using (pagination excluded): <code> // Get the ID of the first generation $gen1_ids = $post-&gt;ID; // Query for second generation IDs $gen2 = $wpdb-&gt;get_col( "SELECT ID FROM $wpdb-&gt;pos...
You're on the right track. You can do this with just one MySQL query instead of two by joining on the <code> post_parent </code> . Drop this function into your functions.php file, then in your template you can replace your <code> WP_Query </code> call with <code> $results = wpse_84810_get_grandchildren(); </code> , cha...
Best Practice For Querying Grandchildren?
wordpress
I am using <code> $page = get_page_by_title('name') </code> ; to get the contents of a page. When I echo <code> $page-&gt;post_content; </code> none of the content is wrapped in p tags like it is when run threw the normal wordpress loop using <code> the_content( </code> ). Is there a different way I should get this dat...
You can apply the content filters to <code> $page-&gt;post_content </code> like so: <code> echo apply_filters('the_content', $page-&gt;post_content); </code>
The content not wrapped in paragraph tags with get_page_by_title()
wordpress
I have a site with 9000 posts and those posts have external images and they are not stored on my server. These posts have thumbs that show on the homepage. My problem is this: whenever someone visits the site, many text files get created in the cache directory via <code> thumb.php </code> and they go up to 9000 if all ...
Check or add the following two config settings: <code> define('FILE_CACHE_TIME_BETWEEN_CLEANS', 80000); // 8 seconds = automatic removal of files define('FILE_CACHE_MAX_FILE_AGE', 20000); // 2 seconds = max. age of file before removed </code> Update Maybe using something like this code snippet in your <code> thumb.php ...
TimThumb cache directory issue
wordpress
I have set crop in functions.php to resize Images for Posts. Codex from Wordpress: add_image_size , post_thumbnail <code> add_theme_support('post-thumbnails'); set_post_thumbnail_size(100, 100, true); //size of thumbs add_image_size( 'post-thumb', 180, 180, true ); //(cropped) </code> Usage is like below <code> &lt;?ph...
After adding new image sizes, you might need to rebuild your thumbnails. I have used AJAX Thumbnail Rebuild after encountering a similar issue, and it worked fine.
Wordpress Resize Image and show as thumb in post
wordpress
I have a WooCommerce site to sell subscription products. I customized the emails and want to test them out in my email client. Currently I have created a test subscription that renews every day (24 hours). This means I need to wait 24 hours to test my renewal emails. How can I trigger these emails so that I can speed u...
To trigger an off-schedule renewal and therefore trigger the renewal order email, please follow these steps: Purchase the test subscription with either Stripe or a gateway that requires manual renewal payments (e.g. Cheque, Bank transfer). PayPal won't work. Find the subscription key for the newly purchased subscriptio...
Trigger renewal order emails for WooCommerce subscriptions for testing
wordpress
Enabling infinite scrolling is as simple as adding this snippet to the theme's functions.php file (where 'content' is the <code> id </code> of the container that wraps the posts): <code> add_theme_support( 'infinite-scroll', array( 'type' =&gt; 'scroll', 'container' =&gt; 'content', 'footer' =&gt; false, ) ); </code> B...
In an email response, Kris Karkoski, Happiness Engineer (WordPress.com) at Automattic told me, "Infinite Scrolling with multiple columns is not supported in Jetpack at this time."
Jetpack Infinite Scrolling For Multiple Columns On Same Page?
wordpress
I am trying to include categories in search results. I've been searching for hours now with no solution. By "including categories" I don't mean search in a certain category, I mean let's say I have a bicycle store and have many companies included in the site; a user searched for <code> BMX mountain cross </code> for ex...
I'm using this code in my search.php above the main loop: <code> $search_term = explode( ' ', get_search_query() ); global $wpdb; $select = " SELECT DISTINCT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category')"; $first = true; foreach ( $search_term...
Including categories in search results
wordpress
I want to check if current page match at least one of two conditions. I don't want to show js code into about page and into 404 page. For the rest of my pages i show the js code. So, I use <code> ((!is_page(element1) AND !is_page(element2)) </code> then show the js code. Element1 is a slug of one specific page and elem...
I think this would do : <code> if ( is_page( 'element1.php' ) || is_404() ) { // do that if page is using template page element1.php or is 404 } </code>
How to check with is_page if 404.php is loaded?
wordpress
I couldn't find an answer relating to this, maybe I just didn't come across it yet. So the setup of the site I am working on at the moment: The Front Page is not set, is default. I can't change this because of the way the template functions, it would be too much work for me to change it. The site already has categories...
In my opinion you should create a new page-child.php and new categories just for that. And assign that page to the blog posts and the new GrupOf categories in use. Not sure if there is any better solution at least this one will not compromise the rest of the site. But wait a bit more for some replies maybe someone has ...
Multiple Categories under one URL, where 'Front Page' is used already
wordpress
I'm adding custom pages in WordPress and trying to handle WordPress with my own CMS. I'm using all WordPress' hooks to manage all these things. Now, I can make a custom post saying "a new album" but I don't know how to give a post name to it. The database entry of <code> post_name </code> in the <code> wp_posts </code>...
Thanks for reply to both of you. I tried to use only <code> sanitize_title </code> function but it repeats when I want to add the same name post so I did something like below in my custom commands: <code> $post_name1 = sanitize_title($_POST['subcategory']); $post_name2 = wp_unique_post_slug($post_name1, $_POST['idofalb...
How to get postname in custom page?
wordpress
I'd like to allow users to add functions to the theme I'm developing, but don't want users to change functions.php directly, as this file may be updated with theme updates. In other words, I'd like this to work in a similar fashion to custom CSS files. How can I setup a user-functions.php file for users and ensure thos...
My suggestion would be to use <code> get_template_part </code> . I think that is the closest you can get to what you want. You may be able to just drop <code> get_template_part('userfuncts'); </code> into your <code> functions.php </code> . That will load <code> userfuncts.php </code> from your theme's main directory, ...
Allow users to add custom functions to wordpress theme
wordpress
I've just noticed that on my paginated posts, only the main page gets indexed in Google. The paginated posts "post-title/2" and "post-title/3" for example, do not get indexed. On closer inspection, it appears that Wordpress creates the same canonical URL for all pages in a paginated sequence. So, the canonical for page...
You will need to replace the default <code> rel_canonical </code> function to do this: <code> function wpse_84647_rel_canonical() { /* Only affect singular posts. Exit early if Yoast SEO is doing this for us */ if ( ! is_singular() || class_exists( 'WPSEO_Frontend' ) ) return; /* Get the post permalink */ $post = get_q...
Multi-page posts do not get indexed by Google due to canonical URLs
wordpress
I have a product loop in a certain page, and I want to filter its categories via URL such as: <code> mysite.com/products // Shows all products mysite.com/products/sculptures // Shows only sculptures mysite.com/products/sculptures/2 // Shows only sculptures paged 2 mysite.com/products/paintings // Shows only paintings <...
Try this code: <code> add_filter( 'query_vars', 'my_query_vars' ); function my_query_vars( $vars ) { $vars[] = 'catname'; return $vars; } add_action( 'generate_rewrite_rules', 'my_rewrite_rules' ); function my_rewrite_rules( $wp_rewrite ) { $products_page_id = 1; //your product's page ID $wp_rewrite-&gt;rules = array( ...
URL Variables in a Certain Page
wordpress
I am an intemediate website builder and have been working with wordpress for a few years. I am attempting to build a website (for myself) that is data intensive. All I've built to date are sites that have 20-30 categories, and several pages. The new site is a business directory that will cover 50 U.S. States and have 2...
First, what you don't want to do is create a post type per state, in fact you want your states to be associated with a taxonomy (one taxonomy called locations with each state being a term that belongs to that taxonomy). Therefore... In this scenario I would create a post type named dealer or companies (if the type of b...
Building a Data Intensive Website with Wordpress
wordpress
I am trying to check if a parent Page has children. If it has children I would like to echo the children as a bulleted list with links to each child (basically a menu). Right now I have the following code in loop-page.php and it checks if the Page has any children and returns an array with the children. I use an if sta...
Well you just need to run a <code> foreach </code> loop over your <code> $children </code> but WordPress has a build in function for this already called <code> wp list pages </code> . For example: <code> $children = wp_list_pages('title_li=&amp;child_of='.$post-&gt;ID.'&amp;echo=1'); if ($children) echo '&lt;ul&gt;' . ...
Find the Children of a Page then Echo it as a Bulleted List of Links (menu)
wordpress
I have used this function below for a while now on normal WordPress installs. It simply blocks users with specific user roles, and redirects them to the home page of the site. <code> function wpse23007_redirect(){ if( is_admin() &amp;&amp; !defined('DOING_AJAX') &amp;&amp; ( current_user_can('subscriber') || current_us...
All your role checks are relative to the user roles in the sub site in which I assume you are not a user. You should also check for <code> is_super_admin() </code> <code> if( !is_super_admin() &amp;&amp; (is_admin() &amp;&amp; !defined('DOING_AJAX') &amp;&amp; ( current_user_can('subscriber') || current_user_can('media...
Dashboard blocker on network multisite for specific user roles
wordpress
The Plugin save the Images to /PLUGINNAME/images but i want that it moves to /uploads The Code inside the Plugin is this here <code> define('WPR_URLPATH', WP_PLUGIN_URL.'/'.plugin_basename( dirname(__FILE__) ).'/' ); $wpr_saveurl = WPR_URLPATH . "images"; $wpr_cache = ABSPATH . "wp-content/plugins/". plugin_basename( d...
What is "the plugin"? Anyhow , you need to change <code> WP_PLUGIN_URL </code> to <code> wp_upload_dir </code> in your <code> define </code> . You can read more here: http://codex.wordpress.org/Function_Reference/wp_upload_dir
Define Folder to save Images
wordpress
Given a site running on server A and server B with a load balancer, shared database/etc, and a regular wp-cron task, how would I make sure that wp-cron only runs on server A, never on server B?
I'm currently testing this in wp-config.php: <code> if ( php_uname('n') == 'wp4' ) { define('DISABLE_WP_CRON', true); } </code> Where wp4 is the name of the second server in the setup
Force Cron to run only on one server
wordpress
I'm having a problem with adding an excerpt counter to the excerpt field. It may be a conflict with another plugin, but basically it screws with other jquery if the excerpt field doesn't exist (e.g.: when it's a page which doesn't have an excerpt). Some issues that occur are: kills admin nav fly-out, media button doesn...
You can use post type conditional tag: <code> if ( 'post' == get_post_type() ) </code> Complete: <code> function excerpt_count_js(){ if ( 'post' == get_post_type() ) { echo '&lt;script&gt;jQuery(document).ready(function(){ jQuery("#postexcerpt .handlediv").after("&lt;div style=\"position:absolute;top:0px;right:5px;colo...
How to add an admin function only to posts, not pages?
wordpress
I am trying to create a single.php file for a specific category on my site. Instead of loading the single.php file I want WP to return that category in a file called single-category-53.php (the actual category id=53). I allow the selection of multiple categories on the site, and with the help of Hikari's permalink plug...
I think this does what you want: <code> function ag_templates( $template = '' ){ global $post; $meta = get_post_meta( $post-&gt;ID, '_category_permalink', true ); if( 53 == $meta ){ $template = locate_template( array( "single-category-53.php", $template ), false ); } return $template; } add_filter( 'single_template', '...
How do I create a single.php for a specific category?
wordpress
I am using the Widget Logic plugin to display a widget only on certain pages. I use the condition <code> is_page(10,16,19) </code> to specify the pages I want the widget to display on. However, the widget does not display on these pages. I have double checked the page ID is correct, and I have cleared my browser cache,...
Refer to the <code> is_page() </code> Codex entry . You need to pass multiple Page IDs as an array : <code> is_page( array( 10,16,19 ) ) </code>
Widget logic not working
wordpress
Given how WordPress is written and how it interacts with a database and given how its not very much OOP oriented, is there a way to unit test a theme? is there a way unit test a framework (not a theme framework) that interacts with WordPress, that is, for example, can you write a unit test for dealing with the loop, de...
There is nothing stopping you from writing your own unit testing for themes/plugins using PHPUnit or some other testing platform. As for WordPress, it has an official Unit Tests here: http://unit-tests.svn.wordpress.org/trunk/ https://github.com/kurtpayne/wordpress-unit-tests (github mirror) There are several build scr...
PHP unit testing WordPress?
wordpress
Is there a way to customize the email content and subject for the welcome and verification emails sent during the registration process for Wordpress? I'd like to hook or filter in without using a plugin or the "pluggable" feature. If someone could point me in the right direction, I'd be very appreciative. Thanks!
So I think the answer is no, you aren't able to do this in a safe manner.
Create custom welcome email without a plugin
wordpress
How can i display wath i am searching in a Search Theme. Ex: I search for Keword : Battleship Result : Your results retrive (3 posts) with the subject Battleship.
Add the following code to your template's search.php - somewhere before the loop: <code> &lt;?php global $wp_query; echo 'Your results retrive ('.$wp_query-&gt;found_posts.' posts) with the subject '.get_search_query().'.'; ?&gt; </code> If search.php does not exists in your template's directory, either copy archive.ph...
How can i display wath i am searching in a theme
wordpress
I am using WP rewrite rules for my custem arguments, But when I am trying to generate permalink like this: <code> add_query_arg(array( 'type' =&gt; 'foo', 'paged' =&gt; 2, ),get_permalink($id)) ; </code> It returns still: <code> mysite.com/products/?type=foo&amp;paged=2 </code> But I need to turn it into this: <code> m...
I'm affraid this "nasty" solution would be the most effective than trying to write some cool function that will translate your permalinks into pretty permalinks: <code> $permalink = rtrim( get_permalink( $id ), '/' ) . '/foo' . '/2'; </code> The rtrim part (removing trailing slash) is just for to be sure there are not ...
How to Add Rewrite Ruled Argument Into Permalink Properly
wordpress
I've been having a lot of trouble getting a <code> WP_Query </code> running with a <code> tax_query </code> on my custom taxonomy. I'm 99.9% sure that my <code> register_taxonomy </code> is correct, as I'm able to tag posts with the right term, see it in the database, and the correct term returns with this function: ht...
First of all, you run <code> register_post_type </code> on <code> init </code> and <code> register_taxonomy </code> on <code> after_setup_theme </code> which is called after <code> init </code> . This means your custom taxonomy will not be available when registering the post type. I would suggest you remove the <code> ...
Custom Taxonomy and Tax_Query
wordpress
I have this news portal i built, and the client want a different size of the featured image. I all ready made my first desired size and they have posted around 200+ posts all ready with that image size. Now, if i change the size it only changes on the new posts / or re upload of the current featured images(which is too...
I use a plugin called AJAX Thumbnail Rebuild . It goes through all of the images in your media library and re-sizes them based on any image sizes registered (including the defaults and anything added with <code> add_image_size() </code> ). It only runs when you manually request it and you can tell it to only rebuild ce...
Resize uploaded images
wordpress
Not 100% sure if this one classes as a php question or is specifically Wordpress... I'm implementing the Wordpress Settings API with a tabbed settings page. I've added a 'reset tab' button, but since the validation is done on a separate page (options.php) I can't seem to figure out which tab I'm on - without adding the...
If <code> tab=tab </code> is in the URL then: <code> global $_GET; var_dump($_GET); // debugging only; You should be able to see what you need. </code> That is pure PHP. If your really need to process that string (I don't know why your would) use <code> parse_url </code> then use <code> parse_str </code> on the <code> ...
Get URL Parameters from referer
wordpress
how can I solve the following problem? I have the category "Events" with the permalink <code> www.myblog.com/events/ </code> and of course single events like <code> www.myblog.com/events/lets-party/ </code> . Now I want to add a custom page "Event Contacts" which should be located below "Events" like <code> www.myblog....
Once wordpress reads the "Events" part of the URL it knows that what follows are posts or subcategories of the events category, and a page is neither, and that is the reason you don't even have an option of doing what you want. Do it as a post instead of a page. Then edit you single.php to have special treatment for yo...
Use an archive as the parent of a page?
wordpress
If a checkbox is checked, it saves a value of 1 for a 'my_checkbox' custom order field in WooCommerce. I'm editing the order admin table and I need to be able to echo a particular icon url if the value of 'my_checkbox' equals 1. I just don't know how to check if the value is equal to one so I can echo the url. Any idea...
WooCommerce orders are posts and behave the same as any WordPress post. So you can use the same WordPress functions to update or read the post meta data. <code> &lt;?php $meta_values = get_post_meta($post_id, $key, $single); ?&gt; </code> For your example I'd suggest: <code> $match_order_meta = get_post_meta( $order-&g...
Run Function if Order Meta Exists - WooCommerce
wordpress
I have registration form code in my <code> functions.php </code> file like this <code> if ('POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; !empty($_POST['action']) &amp;&amp; $_POST['action'] == 'registration') { $error = new WP_Error(); if (empty(esc_attr($_POST['email']))) { $error-&gt;add('regerror','Email is requir...
With that in <code> functions.php </code> you'd probably have to declare <code> $error </code> to be <code> global </code> like so : <code> if ('POST' == $_SERVER['REQUEST_METHOD'] &amp;&amp; !empty($_POST['action']) &amp;&amp; $_POST['action'] == 'registration') { global $error; $error = new WP_Error(); // the rest of...
How to display error messages using WP_Error class?
wordpress
I've written a simple Wordpress plugin to create a new database table. The new table ought to be created when the plugin is activated. When I try to activate the plugin, I get the following error: <code> The plugin generated 3989 characters of unexpected output during activation. If you notice “headers already sent” me...
<code> $wpdb </code> is outside the scope of your plugin file, you need <code> global $wpdb; </code> before using <code> $wpdb-&gt;prefix </code>
The plugin generated x characters of unexpected output, $wpdb not defined
wordpress
I like to do a bunch of stuff only on homepage and archive pages i am working with the genesis framework (not really matters i guess) <code> if( is_singular() ) { wp_die('functions.php'); } add_action( 'init', function() { if( is_singular() ) { wp_die('init'); } }); add_action( 'genesis_before', function() { if( is_sin...
Install my plugin T5 WP Load Order . You get a long detailed list with all available hooks, files, constants, classes, functions and global variables – ordered by first appearance. Whenever you’re in doubt create such a list for the page you are working on, and look up what you need.
How can i know when i can execute what functions of wordpress?
wordpress
There might be an answer here somewhere, but I'm unable to find it, or recognize it if I did. Here's the situation: I have a custom post type, 'region', that displays on single-region.php. Region names are North, South, East, West. I have another custom post type, 'news'. Associated with it is a custom field named 'new...
If I understand you correctly, you want a <code> news_region </code> <code> meta_query </code> <code> IN </code> comparison for <code> All </code> or the first letter of the current region post's title ( <code> N </code> , <code> S </code> , <code> E </code> , <code> W </code> ) <code> // get first letter of this regio...
Query custom post type based on post id and custom field value
wordpress
I am trying to get list of registred taxonomies of current post, I mean: <code> register_taxonomy('color',array('thing'),$args) ; register_taxonomy('shape',array('thing'),$args) ; register_taxonomy('material',array('thing'),$args) ; // etc.. </code> So how can I get the list of taxonomies that registred to 'thing' post...
You are looking for <code> get_object_taxonomies </code> ex: <code> $taxonomies = get_object_taxonomies('thing') ; print_r($taxonomies) // Show "color,shape,material".. </code>
List of Registered Taxonomies of Current Post
wordpress
Is it possible to use <code> $items = new WP_Query( $query_args ); </code> with <code> &lt;?php if(have_posts()): ?&gt; &lt;?php while (have_posts()) : the_post(); ?&gt; </code> without changing the loop to be <code> &lt;?php while ($items-&gt;have_posts()) : $items-&gt;the_post(); </code> Thanks.
<code> global $wp_query; $original_query = $wp_query; $wp_query = null; $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); the_excerpt(); endwhile; else: echo 'no posts found'; endif; $wp_query = null; $wp_query = $original_query; wp_reset_postdata(); </code> http...
Use WP_Query with have_posts()?
wordpress
I have a series of sites that I maintain as part of a WordPress multisite install. I'd like to be able to create users accounts that are restricted to viewing only a single one of these sites. Is this possible? Once this is accomplished, is there a way to determine this permission status programmatically? I'd like to b...
Use <code> is_user_member_of_blog() </code> to check if the current user has been assigned to the blog in <code> wp-admin/network/site-users.php </code> . Then hook into <code> template_redirect </code> and run the test: <code> add_action( 'template_redirect', function() { if ( ! is_user_member_of_blog() ) die( 'Please...
Restrict users on multisite WordPress install
wordpress
I created a custom loop for a particular category. Can I create a list of those posts -- kind of like a table of contents -- and have it link to that service in that loop? Pagination is not used. My current loop is created with this function (I'm sure my function could be more efficient and cleaner -- I'm still learnin...
I ended up creating two loops and utilizing anchors. I'm not sure if it's the most efficient way of doing things, however, it works. <code> add_action( 'genesis_post_content', 'child_do_content' ); // Adds your custom page code/content function child_do_content() {?&gt; &lt;ul class="multicol"&gt; &lt;?php $custom_quer...
Custom loop page with post navigation
wordpress
I've started fully integrating the Wordpress Theme Customisation API into my Wordpress theme and it's phenomenal. One issue I've encountered is that including the default colour picker is great, but I am trying to determine how to change the configuration options for the Iris colour picker being used. By default the co...
The color picker thing is registered as a jQuery UI widget, so you could modify its prototype object before the widget is used in the page: <code> add_action('customize_controls_print_footer_scripts', function(){ ?&gt; &lt;script&gt; jQuery(document).ready(function($){ $.wp.wpColorPicker.prototype.options = { border: f...
Modify Javascript Configuration Options for Theme Customizer Colour Picker
wordpress
To optimise the speed of my platform (beyond caching, database optimisation, JPEG compression, CSS sprites etc), it has come to my attention that disabling the <code> wptexturize() </code> function may give some minor results. We can disable this function by using this script (written by our own "stackexchange-url ("ob...
<code> wptexturize() </code> (in <code> wp-includes/formatting.php </code> ) tries to convert typewriter quotes <code> " </code> and <code> ' </code> into typographically correct pendants like “ or «, depending on current translation files. If you cannot type correct quotes, you should not disable it. There are some re...
Safe to disable wptexturize?
wordpress
I've been having trouble finding a good tutorial on how to back-up a WordPress database using IIS as the web server. I installed WordPress using IIS's web platform installer and now I can't even find where the database file resides. I've been doing everything under a local development if that helps. So my question is, ...
I was able to find the name of the database in word-press's wp-config.php file under the and was able to create a back-up of the file using MSQL workbench and the tutorial found here http://community.discountasp.net/showthread.php?t=11972 .
How to back-up a database on IIS
wordpress
I am making theme for hotel and i made custom metabox with list of various custom fields that i would need in posts. What i did is i made a list of fields like booking wifienabled coffe pool spa and so on... Problem is that currently i can show those custom fields in website frontend only by order how i added them in a...
In this example of repeatable custom fields , we can see that the following jQuery is needed: <code> $('#repeatable-fieldset-one tbody').sortable({ opacity: 0.6, revert: true, cursor: 'move', handle: '.sort' }); </code> And the HTML it controls is (simplified): <code> &lt;table id="repeatable-fieldset-one" width="100%"...
Arrange custom fields with drag and drop?
wordpress
I want to programmatically add an item to the cart, and that item is not a product.. It's a custom post type that I am creating. I think I'm going in the right direction by using the Jigoshop cart class. Found in the jigoshop folder under classes/jigoshop_cart.class.php. The problem is that I'm not sure exactly how to ...
Short answer: You can't. Long answer: Jigoshop is designed to only allow checkout of our "product" CPT. In reality, you should have been looking at Jigoshop's template_functions.php file which has our add to cart functions. For security reasons, Jigoshop has checks, absolutely everywhere that the CPT is in fact Jigosho...
Using Jigoshop, how can I add a custom post type to the cart via code?
wordpress
How can I change the post limit for taxonomy.php from that which is defined in the settings page? Currently I have 10 posts displaying per page, which is fine for the blog part of my site, but I want to show all posts when the user is on taxonomy.php, is there a function that can achieve this?
Use the <code> pre_get_posts </code> hook to check is you are in a taxonomy term archive and change the number of posts ex: <code> add_action('pre_get_posts', 'change_tax_num_of_posts' ); function change_tax_num_of_posts( $wp_query ) { if( is_tax() &amp;&amp; is_main_query()) { $wp_query-&gt;set('posts_per_page', 5); }...
Function to limit the number of posts in taxonomy.php
wordpress
I have just started out with a VPS running centos 6.3 to host my blog and play around. After Installing WordPress 3.5.1, when I tried to install some plugins from the admin console, it complained of the folders in wp-content (upgrades, plugins, themes ..) not being writable. I changed the owner and group of these folde...
As per the following from http://codex.wordpress.org/Hardening_WordPress#File_Permissions /wp-content/ User-supplied content: intended to be completely writable by all users (owner/user, group, and public). Within /wp-content/ you will find: /wp-content/themes/ Theme files. If you want to use the built-in theme editor,...
Are these wp-content permissions safe?
wordpress
I enable the debugs, and i have these that describe below. In the <code> wp-config.php </code> write : <code> define('WP_DEBUG', true); define('WP_DEBUG', false); </code> 1) Notice: Undefined index: type in C:\xampp\htdocs\mywebsite\wp-content\plugins\oqey-gallery\gallcore.php on line 252 on line 252 : <code> //media_u...
Number 1 is not wordPress, but PHP. <code> $_GET['type'] </code> is undefined. Use an <code> isset( $_GET['type'] ) </code> conditional. Number 2 the error message tells you exactly what to do. Instead of calling: <code> add_custom_background(); </code> ...call: <code> add_theme_support( 'custom-background' ); </code> ...
Resolve the debugs
wordpress
I have a german / french blog. I installed the german WordPress version, so I already had de_DE.mo and de_DE.po in wp-content/languages. After I realized that the content of a comment's <code> &lt;time&gt; </code> -element wasn't translated, I googled and downloaded fr_FR.mo and fr_FR.po and put them in wp-content/lang...
No matter what languages your site are in, when using WPML you should never install a localised WordPress version, instead you should just install the default one (i.e. US English). Also make sure that you didn't change the LANG definition in your <code> wp-config.php </code> file, so that should read: <code> define ('...
WordPress Translation to french, at -> à not working
wordpress
How can i retrive the categories from a post_type that i select. I have a Custom_field - categorie_serial <code> &lt;?php $values = get_field('categorie_serial'); if($values) { echo '&lt;ul&gt;'; foreach($values as $value) { echo '&lt;li&gt;' . $value . '&lt;/li&gt;'; } echo '&lt;/ul&gt;'; } // always good to see exact...
This should get you started <code> function my_cpt_cats() { $parent = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $args = array( 'type' =&gt; 'post', 'child_of' =&gt; $parent-&gt;term_id, 'parent' =&gt; '', 'orderby' =&gt; 'slug', 'order' =&gt; 'DESC', 'hide_empty' =&gt; 1, 'hierarchica...
How can i list the categories of a post type, the taxonomy
wordpress
I'm working on a products showcase website, and in my index I have this snippet of code for my two variables ($price for the price, $buynow for the URL) <code> &lt;div class="buyitnow"&gt; &lt;?php global $post; $price = get_post_meta($post-&gt;ID, 'price', true); $buylink = get_post_meta($post-&gt;ID, 'buynow', true);...
The problem is that you're trying to perform a math operation on a string ('TBA') so the result is going to be 0. Try testing if the value is numeric by using the php function is_numeric(). You can see the docs for that function here . So in your code do this: <code> if (is_numeric($price)) { ...format the number } els...
$TBA Getting Translated to $0 (Custom Fields)
wordpress
From everything I've read, you should only translate text strings via the WP translation functions like <code> _e() </code> or <code> __() </code> . However, I need a way to translate content submitted via a form. Is there some solution that will allow me to translate text outputted in a variable? Here's what I'm doing...
You cannot translate text you don’t know. The translator must know the text before it was submitted – impossible. The only solution is: add all language strings manually for each sub site.
Using Variable in WordPress Translate Functions
wordpress
I'm using the below code to get all the pages under the custom taxonomy terms, and it shows all the pages. What i want is to limit this and gets only say the last two pages published under the custom taxonomy. The posts_per_page=1 is not working here and show all pages. <code> &lt;?php $post_type = 'page'; // Get all t...
Your <code> WP_Query </code> is formed incorrectly. See WP_Query Taxonomy Parameters . Try this code: <code> &lt;?php $post_type = 'page'; // Get all the taxonomies for this post type $taxonomies = get_object_taxonomies($post_type); // names (default) foreach( $taxonomies as $taxonomy ) : // Gets every "category" (term...
Set posts_per_page in WP_Query for custom taxonomy
wordpress
Im working with a project where i want the wp_nav_menu to output other css classes for current_page, current_ancestor and remove other stuff like page-id and menu-id. I have get some stuff working like remove the unessesary classes and id:s using a custom Walker. But i cant get the current_ancestor to change to another...
I believe the <code> current-ancestor </code> etc. classes are not added by the walker itself, but rather by <code> wp_nav_menu </code> which is calling <code> _wp_menu_item_classes_by_context </code> . Thus, your best bet is probably to add a filter to <code> nav_menu_css_class </code> and remove/replace <code> curren...
Change class-name on "current_ancestor" in wp_nav_menu
wordpress
I'm using Pods plugin (ver 2.2) to create some 'Pods' or Advanced Content Types , as they would refer to it, which are like custom post types but are actually separate from WP, blank slate, in their own tables. Each content type has at least two fields. What I wanted to know is how do I display those field inputs in th...
To customize which fields are shown in Pods UI, you can filter the default UI options through this filter / function combination. Overriding the $ui array with the options you wish to customize, this can be pretty quick and easy. <code> function pods_ui_test ( $ui ) { // Test on UI Column $ui[ 'fields' ][ 'manage' ] = ...
Pods CMS: How to add custom column to Adnvanced Content Type
wordpress
I'm using WP function fetch_feed to retrieve a feed and display its items. <code> &lt;?php /* include the required file */ include_once(ABSPATH . WPINC . '/feed.php'); /* specify the source feed */ $rss = fetch_feed('FEED_URL'); /* checks obj. is created */ if (!is_wp_error( $rss ) ) : /* specify number of items */ $ma...
Ok, found. I spent hours on this but I managed to find the solution. The command I was looking for was $rss-> enable_order_by_date(false);. So you should set (for benefit of the community): <code> &lt;?php /* include the required file */ include_once(ABSPATH . WPINC . '/feed.php'); /* specify the source feed */ $rss = ...
fetch_feed: retrieve entries in the appearing order, not chronologically
wordpress
i got close solution for this question from this link "stackexchange-url ("How to add a textarea to only one of the fields of this custom metabox?")", but with different code and he use new metabox, i need to see value on custom fields also, with this solution i cant see on "custom fields box". so i use this code: <cod...
i got the solutions, <code> array( 'shortdesc', 'shortdesc' , 'textarea'), </code> and add new function for text_area: <code> function text_area ( $args ) { global $post; // adjust data $args[2] = get_post_meta($post-&gt;ID, $args[0], true); $args[1] = __($args[1], 'fp' ); $label_format = '&lt;label for="%1$s"&gt;%2$s&...
Textarea type on one field custom add_meta_box?
wordpress
Im having a problem where for some reason, a basic loop im trying to add to a sidebar keeps....keeps looping on interior pages (single and page .php ) but not on index.php. on index.php (home page) is fine. for example, i wanted the loop to populate an unordered lists line items, so i went about it like this: <code> &l...
Add <code> wp_reset_query(); </code> after your loop to prevent other loops on the page (for example, the navigation) to break. <code> &lt;?php query_posts( array ( 'category_name' =&gt; 'left_sidebar', 'posts_per_page' =&gt; 4, 'orderby=menu_order' ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt; ...
wordpress simple loop, huge issues
wordpress
I had a quick question regarding how you are supposed to load in scripts with Wordpress. I am developing a theme and I know that the best way to do this is to use the "wp_register_script/wp_register_style" methods and then to enqueue them with "wp_enqueue_script/wp_enqueue_style". Lastly, you add them to the action "wp...
I would't be affraid of wp_enqueue function itself, not PHP slowdown. But enqueuing more javascript files really matters. But not from the PHP point of view. Each website (even in pure HTML) is getting slower with each other request till it brings all the files. The firs request is HTML file (that's why we use gzip com...
Is the wp_enqueue method efficient?
wordpress
I know that the following mysql query produces the exact results I wish to echo within single.php: <code> SELECT meta_value FROM `wp_taxonomymeta` WHERE `taxonomy_id` =565 AND `meta_key` LIKE 'baseurl' </code> First, I need to be able to use $wpdb to output that result, and no matter what I try I can't get it to work. ...
Catchable fatal error: Object of class stdClass could not be converted to string in /wp-content/themes/new/single.php on line 22 This is because <code> $wpdb-&gt;get_row </code> returns an object by default and you can't echo an object. Changing <code> echo $toc </code> to <code> echo $toc-&gt;meta_value </code> will g...
How do I display a custom field from a custom taxonomy in single.php?
wordpress
Can someone please direct me to a resource or give me some pointers on: How to upload a csv file to wordpress (media uploader or alternate methods, ajax powered preferred) Access that file so I can read the contents I am not looking for a plugin as this is a custom file that I need to read and process inside a plugin. ...
Enable upload of CSV files, which are not in the default allowed files ( see here ) Hook into add_attachment action hook to detect when the desired file is uploaded Do whatever you need to do using that hook, then trigger wp_delete_attachment once the file has been processed. Depending on what you want to do, it may be...
Upload a custom csv file, read contents and delete that file
wordpress
I have been trying to find a way to access the the maximum width of a large image as set on the media settings page? In my theme I am grabbing images from a server and have the ability to specify the size when I grab them. I want to grab the image with the width set for the large image size on the media settings page.
The sizes are stored in the options table in the database, so you can grab values with <code> get_option('large_size_w'); </code> The values stored in the DB are: thumbnail_size_w thumbnail_size_h medium_size_w medium_size_h large_size_w large_size_h
How do I access the media settings
wordpress
My wordpress blog homepage has thumbnail gallery. I want add adsense image ad code to 5,10 place. Below code from my index <code> &lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class('thumb'); ?&gt;&gt; </code> I found BELOW code from stack...
Here is a slight variation of stackexchange-url ("my other answer"). First we register two new widget areas, sidebars in WordPress-speak. <code> add_action( 'widgets_init', 'wpse_84250_register_ad_widgets' ); function wpse_84250_register_ad_widgets() { // used on the first page of main loop only register_sidebar( array...
Add Adsense code in index.php
wordpress
I am using this following code in my functions file to hide and add some custom columns to my post-edit screen in wp-admin. I am now trying to get the post list to sort by a post meta field (last name). I've read through many tutorials on how to do this, but I can't find anything that matches what I have. I don't need ...
Something like this should work: <code> function wpa84258_admin_posts_sort_last_name( $query ){ global $pagenow; if( is_admin() &amp;&amp; 'edit.php' == $pagenow &amp;&amp; !isset( $_GET['orderby'] ) &amp;&amp; !isset( $_GET['post_type'] ) ){ $query-&gt;set( 'meta_key', 'last_name' ); $query-&gt;set( 'orderby', 'meta_v...
Auto sort the wp-admin post list by a meta key
wordpress
I have wp_users table which has a column ordering.I came to know that get_users() returns all the users. I am using it like get_users ('orderby=ordering') I got help form this link But unfortunately it is not sorting on ordering column. Any help? Here is my code <code> foreach (get_users ('orderby=ordering') as $user) ...
I think modifying the default tables in your WordPress install is a bad idea. Generally you should never modify the database or the core code, but instead use API functions to get the desired functionality. In this case that you be using the user meta fields to store a sort order for each user. The easiest way to do th...
Using get_user in wordpress with sorting
wordpress
I'm trying to query all-in-one-event-calendar's custom post type ai1ec_event and normal wordpress posts in a slider on my home page. That works pretty well. Now I want to query only the posts with the custom field value "teaser", but that returns just normal posts, not the events. <code> &lt;?php query_posts( array( 'p...
I'm afraid WP_Query is not able to fetch (Posts with custom field) or (ailec_even). You'll have to query the firs one, than the second one and merge those arrays. Use WP_Query instead of query_posts. I've just tried it on my local installation and this code called from index.php of twentytwelve works (brings post with ...
query posts and custom post type with meta key
wordpress
I try to align content side by side. I tried this solution from the Wordpress forum but it is not working for me: http://wordpress.org/support/topic/how-can-i-display-two-pictures-next-to-each-other
I had to guide a user through this recently, some tricks that I found: 1) Make sure the HTML is clean, that fidding in the visual editor has not added in extra paragraphs or alignments or whatever. In fact, take out all the alignleft etc. you can, get it back to a virgin state. 2) In the visual editor, select the image...
How to get twenty ten content side by side (images and/or text)?
wordpress
I'm really trying to find a way or find a plugin (that works) that puts in different rel=author and/or rel=publisher attributes for a blog with multiple authors. That way, in a Google SERP, an article I wrote might show up as: <code> Jason Weber Meta Title of that post (my picture) Meta description of that post </code>...
Well, you can try my plugin ;), but almost every SEO plugin includes this functionality now, and there are several plugins which are kind of dedicated to it. If you want to code it yourself for whatever reason, all you need is basically to add a field in the user profile admin page in which the user google profile url,...
Is there a way to input different rel=author and rel=publisher attributes for a WP blog w/ multiple authors?
wordpress
I ran a custom loop the other day to get some twitter information. Since I was running the code in a template and that template was being called from another loop, I was able to get the template data by doing this <code> $content = $template-&gt;post_content; echo $content; </code> I figured this would be better than s...
The <code> pre_get_posts </code> action hook only allows you to modify the $query object . Any formatting or output of data is done in the template file within the loop . When you are in the loop you have access to various template tags that output the post data formatted (filters applied). <code> if ( have_posts() ) :...
pre_get_posts returning unformatted page
wordpress
I have my products set to manage inventory. Is there an option somewhere to simply make the product pages state "In Stock" rather than "X In Stock"? Or is that just set in the theme (I'm just using Twenty Twelve at the moment)?
There is actually a setting for this, found under WooCommerce, Settings, Inventory, Stock display format.
Manage Inventory Without Displaying Levels
wordpress
<code> &lt;?php wp_head(); ?&gt; </code> from my default wp theme generates <code> &lt;script type='text/javascript' src='http://example.com/wp-includes/js/comment-reply.min.js?ver=3.5.1'&gt;&lt;/script&gt; &lt;script type='text/javascript' src='http://example.com/wp-includes/js/jquery/jquery.js?ver=1.8.3'&gt;&lt;/scri...
To disable <code> comment-reply </code> go to <code> Discussion Settings </code> and disable <code> Threaded (nested) comments </code> . Google-hosted jQuery: <code> function my_scripts() { wp_dequeue_script('jquery'); wp_enqueue_script( 'jquery', // name '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', //...
How to modify the paths of js from twentytwelve theme?
wordpress