question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I have page Example (ID=443, slug=example) that is configured, through <code> Dashboard-&gt;Settings-&gt;Reading </code> , as the home page of my WP site. I also have the following rewrite rule configured: <code> [(example)/(view-section)] =&gt; index.php?pagename=$matches[1]&amp;foo=1&amp;bar=2 </code> I have a shortc...
The problem has nothing to do with the rewrite rules (though I would suggest using <code> add_rewrite_rule() </code> rather than the more low level approach of altering the rewrite array directly. The same for <code> flush_rewrite_rules() </code> . Also, although as you have it the rules are only flushed once - it woul...
Rewrite Rules problem when rule includes homepage slug
wordpress
I'm trying to use <code> meta_query </code> to return all users that have registered today : <code> $args = array( 'meta_query' =&gt; array( array( 'key' =&gt; 'user_registered', 'value' =&gt; date('Y-m-d'), 'compare' =&gt; '=', 'type' =&gt; 'DATE' ) ) ); $query = new WP_User_Query( $args ); $users = $query-&gt;get_res...
The field <code> user_registered </code> is not a in the <code> *_usermeta </code> table, but the in <code> *_users </code> . Nor do there seem to be any appropriate hooks to alter the SQL statement when using <code> WP_User_Query </code> . It seems you will need to use a direct SQL statement. Another (minor) complicat...
How can I query all users who registered today?
wordpress
On the internet there are thousand of articles on how to insert external scripts using wp_enqueue_script(). Anyway i didn't find anything explanatory on how to add inline, <code> &lt;script&gt; </code> enclosed, scripts. I use to add them in the middle of the page code but i suppose it's not the most elegant way and th...
Even though mrwweb is correct and that technique should be used, in reality nothing is perfect and there are times when inline scripts and styles are used. You can use <code> wp script is </code> to check for a script and output them in the header or footer using <code> wp_head </code> or <code> wp_footer </code> . You...
Where and how to put inline js in pages
wordpress
I have a custom post type called "course" and I would like to create a date based archive similar to the default post archives which look like mysite.com/2012/05. I want to use urls like mysite.com/ course /2012/05. How can I do this using the WordPress rewrite API ? While avoiding plugins. This solution is very close ...
Had similar situation not long ago. stackexchange-url ("Check the answer to my question here"). I believe that will solve your problem.
Custom Post Type Date Based Archive URL rewrite
wordpress
I'm wondering how you go about creating an info/help message at the top of a custom post type in WP's dashboard? I often see these at the top of plugins and Id like to do the same thing for my custom post types if possible ( see image below for example --- Note: Screenshot has been taken from NSP-Code's "Post-Types Ord...
The hook you are after is <code> admin_notices </code> . This is fired at the top of every admin page. If you wish to restrict the notice to certain pages you can use: get_current_screen() to get the current screen. <code> $screen = get_current_screen(); </code> You can wrap the notices in <code> div </code> elements w...
Create an Info/Help message at top of a custom post type
wordpress
I switched my site from categories to taxonomies for my custom post but I am having trouble getting it to work the same way. For categories I could have templates named something like <code> category-travel.php </code> and then have my loop in that file. Now I am trying to replace the category list with something like ...
It looks like your issue is the name of your taxonomy has a capital letter, the first argument of register_taxonomy is to be all lowercase, no spaces as the documentation for the register_taxonomy function mentions here . Change your code to the following and your taxonomy-gallery.php template will work correctly. <cod...
Create an archive page for custom taxonomies
wordpress
I`m trying to construct a json object but are having difficulties with the_content since it returns newlines, which causes the script to fail. The error messages received is: Uncaught SyntaxError: Unexpected token ILLEGAL Example of the json: <code> [ {image : 'http://localhost/wp-content/uploads/2012/04/example.png', ...
To output JSON always the function <code> json_encode( $string ) </code> . The function is not available on all hosts. Don't worry, WordPress offers a fallback in <code> wp-includes/compat.php </code> . That's a wrapper for <code> class Services_JSON::encodeUnsafe() </code> (see <code> wp-includes/class-json.php </code...
How to encode post content as JSON?
wordpress
I have defined a <code> post_view_count </code> meta_key to store the number of post views. I would like to get an array of post ids sorted by <code> post_view_count </code> value to use in the <code> functions.php </code> file. Thanks.
It's easy. :) You would use get_posts function. See WP_Query class for complete list of parameters that you can use. <code> function get_posts_by_view_count() { $ids = array(); $args = array( 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'DESC', 'meta_key' =&gt; 'post_view_count' ); $posts = get_posts( $args ); if( $...
Get post ids sorted by meta_key
wordpress
I have a problem with my code, I want to display 3 specific pages on my homepage but my code is not working.. here's the code.. <code> &lt;?php $args = array( 'post_type' =&gt; 'page', 'post__in' =&gt; array(3,5,7) ); query_posts($args); while (have_posts()) : the_post(); $do_not_duplicate = $post-&gt;ID; ?&gt; &lt;div...
This is an inappropriate use of <code> query_posts() </code> which is only for modifying the main query for the page. Additionally, even if you change your snippet to use <code> get_posts() </code> , your template tags (e.g. <code> the_excerpt() </code> ) won't work as <code> get_posts() </code> isn't a method of loopi...
Retrieve or Query Pages by ID
wordpress
I'm rewriting the question, including exemplary code, I hope it will be easier to understand now. 1. My shortcode: <code> function testid_shortcode( ) { global $post; return $post-&gt;ID; } add_shortcode('testid', 'testid_shortcode'); </code> 2. The issue: I'm using the shortcode on page Example1 [ID=1]: <code> [testid...
The global $post object is from the current query, so what you're seeing is the expected behavior. If you always want the shortcode to return the post_meta from ID = 1, then you should just hardcode that into the shortcode like in @Chris_O's answer where you just save a variable that equals 1 and pass that to <code> ge...
How to get ID of the page included with get_page()?
wordpress
I'm using permalinks in WP as: <code> domain.com/category/post_name </code> The issue is that post names have non-latin characters such as chinese, hebrew, and arabic . So it encodes them to something like: <code> %20%18%6b%20 </code> therefore it counts every symbol's character as an actual character, ending up with 3...
Permalinks like <code> http://example/שָׁלוֹם </code> are actually working in my WordPress 3.3. Could be the remove_accents() improvements for i18n permalinks . As Sean &amp; Steve noted, make sure you're using WordPress ≥ 3.3 make sure your .htaccess file contains a rule similar to <code> RewriteRule . /index.php [L] ...
Wordpress slug issue with non-latin characters
wordpress
I have one loop on my homepage that I use infinite scroll to paginate. To keep the load time of the homepage down, I want to load a smaller initial amount than when the infinite scroll is triggered for the first time. So on page load I want 10 posts loaded and then every trigger after that I want the post_per_page to e...
stackexchange-url ("Add a parameter") to the <code> href </code> URI for the next posts link per JavaScript. For example <code> ?ppp=25 </code> . Add a filter to <code> pre_get_posts </code> , check if <code> ppp </code> is set (and a positive integer) and change the <code> post_per_page </code> parameter accordingly. ...
Use two different post_per_page limits with infinite scroll
wordpress
I'm using the lovely Imbalance theme from WPShower. I am able to make almost all the modifications I need through files and filters in the child theme I created. However, there is a typo that appears in multiple files: <code> &lt;?php printf(__('&lt;span&gt;Filled under:&lt;/span&gt; %s'), get_the_category_list(', '));...
You can override it, but you'll have to create Child-Theme versions of <code> archive.php </code> , <code> attachment.php </code> , and <code> single.php </code> . Since it's a translation string, you might be able to do something hackish, like provide a en_US.MO file that translates "Filled under" as "Filed under" (or...
Override typo in multiple parent theme files?
wordpress
I'm having issues where multiple copies of jQuery are being loaded onto the page via plugins that require jQuery. I Just want to confirm that if I have 3 plugins active on my page, that all properly use wp_enqueue_script to load jQuery, will the library be included only once or 3 times?
If all three plugins load jQuery properly using <code> wp_enqueue_script("jquery") </code> then only one copy of jquery will be used. If you are seeing three copies then some plugins are not playing nice.
Plugins loading multiple copies of JQuery
wordpress
To reduce http requests, I'm combining all scripts that my theme uses into a single minified .js file each time theme options is saved. One of the files in this .js is the jQuery library. Rather than including jQuery as a separate file (using wp_enqueue_scripts), I'm including the wordpress core jquery file as part of ...
You really shouldn't do it, it's not a good practice. You should always use the jQuery version supplied with WordPress package. If you use your own jQuery version in your own file you would have to update it manually every time the jQuery gets updated in WordPress package. If you really insist on doing that, the most s...
How to tell WordPress that jQuery exists on the page to avoid duplicates via wp_enqueue_scripts
wordpress
In a plugin I want to build, it deals with contests. A contest has a date on it. Does WordPress have a feature in it where it can run a piece of code every day without requiring someone to create a cron job? Basically I'm wondering if, when you build a blog with WordPress, if WordPress.org or Automattic automatically p...
Check out wp_cron and the cron_schedules filter. There are lots of good tutorials out there like this one from WPTuts or this one from Viper007Bond.
How Do I Make WordPress Run an Event Every Day?
wordpress
I am working modifying an ecommerce plugin, and it makes uses of wp_update_user() function, and everytime the function runs another table (created by the plugin), gets updated too. The problem is that the updated data on that second table is incorrect, and I am having troubles finding the part of the code that does it....
<code> wp_update_user() </code> is in <code> /wp-includes/user.php </code> lines 1401-1439. It uses <code> wp_insert_user() </code> (same file, lines 1254-1380) to update the existing user or add a new one if the user doesn't exist. That function is where the various filters and actions affecting user account info live...
Which action does wp_update_user triggers?
wordpress
I have been using this site alot for solving my problems, but this time I did not succeed in finding and answer for my problem. I get and infinite loop when using <code> wp_update_post </code> inside a function that is called on <code> save_post </code> . I know that this is a common issue, but I can't figure out how t...
You can remove the callback from the <code> save_post </code> hook, update the post and then re-add the call back to the hook. The Codex gives an example. <code> add_action('save_post', 'wpse51363_save_post'); function wpse51363_save_post($post_id) { //Check it's not an auto save routine if ( defined('DOING_AUTOSAVE') ...
How to avoid infinite loop in save_post callback
wordpress
I file all the galleries on my blog under the 'gallery' tag. I use the following code (stackexchange-url ("via")) to display the latest 7 gallery posts after the 8th latest post on home page: <code> &lt;!-- Featured post galleries after 8th post --&gt; &lt;?php $homegallery++; if ($homegallery == 8){ ?&gt; &lt;!-- Disp...
Just use the <code> $count </code> variable that you are incrementing: <code> &lt;?php $count = 0; $some_featured_posts = new WP_Query(array('category_name' =&gt; 'apps', 'posts_per_page' =&gt; 5)); while ($some_featured_posts-&gt;have_posts()): $some_featured_posts-&gt;the_post(); $count++; if( $count &lt;= 2 ) the_po...
Show different size featured images (the_post_thumbnail) for 1st, 2nd and 3rd posts?
wordpress
Just a quick question: Can I modify a plugin and submit the modified plugin to directory under another name?
It depends on the license of the source plugin. In case you've downloaded that plugin from Wordpress Plugins Directory, then you can modify and upload it as it inherits the GPLv2 license of Wordpress itself or GPLv2-compatible license of the modified plugin. Here are some guidelines . Also, it's polite to mention the o...
Modify plugin and submit to directory
wordpress
Having a mixed security issue that is affecting functionality in browsers because some of my plugins are loading with http instead of https. I'm running under a multisite setup. Thanks! This is what I have in my htaccess <code> # BEGIN WordPress RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule (.*) https:...
Most likely, what you mean is that some assets (images, JavaScript, etc.) rendered by your plugins are being served explicitly over http. (Please correct me if I've misunderstood). These problems need to be fixed in each of the individual plugins, and the fixes will vary based on how the assets are referred to. There a...
Force Load https Wordpress Plugins
wordpress
I am working on my category template. Here is how I want the page to display: Category Name - <code> this is done </code> The latest post for each category be on top <code> (then styled which I can do) </code> . The Category description - <code> this is done </code> List all the rest of the posts for the category under...
Use WP_Query's built in <code> current_post </code> counter in your loop: <code> while( have_posts() ): the_post(); if( $wp_query-&gt;current_post == 0 ): // this is the first post in the loop else: // this is &gt; first post endif; endwhile; </code> EDIT w/html: <code> &lt;?php while( have_posts() ): the_post(); if( $...
Category Template - Show Last Entry as Featured
wordpress
I have a custom post type with the following capabilities: <code> $capabilities = array( 'read_post' =&gt; 'administrator', 'read_private_posts' =&gt; 'administrator', 'publish_posts' =&gt; 'administrator', 'edit_post' =&gt; 'administrator', 'edit_posts' =&gt; 'administrator', 'edit_published_posts' =&gt; 'administrato...
When using <code> save_post </code> you are usually add/updating user-inputted data from a metabox into the database. When do this you should check that your metabox's nonce is valid. You should also check permissions as <code> save_post </code> is triggered inside <code> wp_insert_post() </code> , and not just when th...
Custom post type: check permissions and validate nonce
wordpress
I've found other questions asking the same thing but I think I followed the method correctly. I created a page called "Splash" (page-splash.php) and another empty page called "Blog" But when I change the settings in "Reading" the main page is working (WP loads page-splash.php correctly) but the the loop in my index.php...
When you use "static front page" are you selecting the actual page you want displayed on the home page? It sounds like you want the "Splash" page as the home page. You should create the Splash page in the Page Edit Screen, select a custom page template if that is what you're wanting to use and save the page. Now you'll...
Static posts page is not working
wordpress
I'm trying to list all posts from a certain category, in a list, on the category page that already lists the posts out in blog form. I'm trying to do it in the header area so that you can get an overall look at the posts on the page. I found this: <code> &lt;ul&gt; &lt;?php global $post; $category = get_the_category($p...
Good news! I think you're making things harder for yourself than they need to be. If I understand your question, you're looking for <code> rewind_posts() </code> . The always useful Digging Into WordPress has a nice summary of it . Because both tasks involve looping through the same query , you don't need <code> get_po...
Listing all posts from current category on page
wordpress
I need to add an option in my theme options panel to set a specific custom menu's links all to nofollow. Does wp_nav_menu() allow this or does it require a custom walker to manually ad rel="nofollow"?
As you can see above, the Advanced Menu Properties are hidden under the Screen Options pull down tab located in the upper-right corner of WordPress Dashboard. NOTE: Make sure that you are in the Menus screen: <code> http://yoursite.com/wp-admin/nav-menus.php </code> W.r.t your question, the Link Relationship (XFN) opti...
How to add nofollow to wp_nav_menu
wordpress
As mentioned on wordpress.org , it is possible to link a thumbnail to its larger self. <code> &lt;?php if ( has_post_thumbnail()) { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '&lt;a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" &gt;'; the_p...
Thank you Jeremy Jared. I applied the following solution, based on yours ( stackexchange-url ("Any good lightbox-like option that works in WP 3.2.1?") ) First of all, now I call my thumbnail with the following code instead of trying to add the link myself: <code> wp_get_attachment_link(get_post_thumbnail_id(), 'thumbna...
Thumbnails and Lightbox
wordpress
Others have asked how to only get stackexchange-url ("parent terms"), but I need to get the deepest term for the post of a specific taxonomy. Is there a way I can only get terms where the number of children = 0?
I have written this function some time ago, it may be a bit sloppy but it does it's job: <code> function get_low_level_term( $taxonomy ) { $term = null; if( is_single() ) { global $post; $terms = get_the_terms( $post-&gt;ID, $taxonomy ); if( count( $terms ) == 1 ) { foreach( $terms as $t ) { $term = $t; } } else { fore...
Get object terms with no children?
wordpress
Clicking the screen options on dashboard, the drop down area has welcome checkbox. So even after hiding the welcome screen, if user chooses to display the welcome screen. It still shows. Is there a way to hide this option completely and turn off the welcome screen? Or otherwise, a way to remove the welcome content comp...
For WordPress 3.5+, adding <code> remove_action( 'welcome_panel', 'wp_welcome_panel' ); </code> to your functions.php removes the Welcome Panel from the Dashboard as well as its Screen Options menu. See http://codex.wordpress.org/Plugin_API/Action_Reference/welcome_panel .
How to remove welcome screen and its screen option checkbox?
wordpress
This is a page template for custom nivo slider, it gives unexpected endwhile on line 1 error. I can't find out whats wrong. <code> &lt;?php /* Template Name: sliderpage */?&gt; &lt;?php get_header(); ?&gt; &lt;div class="span-24" id="contentwrap"&gt; &lt;?php //get_sidebars('left'); ?&gt; &lt;div class="span-14"&gt; &l...
I wasn't able to recreate the error. Maybe it's coming from <code> &lt;?php get_sidebars('right'); ?&gt; </code> I did change your code a little, but it didn't give the "unexpected endwhile" error you spoke of. If it's coming from line 1 I'd guess it's the header.php file? Here is the adjusted code if you want to try i...
Error in Wordprewss loop for page template
wordpress
I am curious without doing a ton of benchmarks, how others feel about using several custom meta fields on a blog post? I am talking strictly performance wise, does it slow things down a lot if using a lot of fields, should we try to keep them to a minimum? Currently for a regular blog post, I have a custom meta field f...
Custom Fields are normally fetched in a single query to the database, so fetching 1 or 10 isn't going to make a lot of difference in performance of your WordPress site. The problem is with doing complex meta queries on existing custom fields; that's when your site would see a performance hit. Obvious, isn't it? Also, l...
Is it bad to use a lot of Custom Meta Fields?
wordpress
How can I add extra parameters after a permalink, specifically if I'm using a custom post type? For example, let's say <code> http://mysite/album/record-name </code> was the permalink. How can I make <code> http://mysite/album/record-name/related </code> not turn up a 404 or redirect? WordPress doesn't seem to call up ...
You can add an endpoint to your URIs to handle special requests. Here is a basic example as plugin. To understand what's going on read stackexchange-url ("Christopher Davis")'s fantastic tutorial A (Mostly) Complete Guide to the WordPress Rewrite API. <code> &lt;?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Endpoi...
Add extra parameters after permalink?
wordpress
I have a site that uses multiple query taxonomy archives. i.e www.sitename.com/taxonomy1/taxonomy2/taxonomy3 Is there a plugin or method to create a dedicated sidebar for each queried taxonomy archive? Essentially, there will be 1000 or so archives and i would like to be able to create a unique sidebar for each. Is thi...
I've had luck dynamically creating sidebars using a foreach loop. You'd do something like this (untested) in your functions.php file: <code> $my_terms = get_terms( 'my_taxonomy_name' ); if( ! is_wp_error( $my_terms ) ) { foreach( $my_terms as $term ) { register_sidebar( 'name' =&gt; $term-&gt;name . ' Archive Sidebar',...
Can you have seperate sidebars for multiple taxonomy archives?
wordpress
How to I create a many-to-many relationship between two custom post types? Give type A and type B, I'd like to be able to show all B's that relate to a given A, and all A's that relate to a given B.
WordPress doesn't have a way to natively do many-to-many relationships, have a look at the Posts 2 Posts plugin to enable this.
Many to Many Relationship between Two Custom Post Types
wordpress
Hi I am building a jquery accordion which works fine on my site. However I am now trying to introduce conditionals to only enable it on posts and pages, however it doesn't work, it seems the conditionals don't detect that it's a page. The code is here: http://pastebin.com/9anYAKa1 <code> function faq_start_shortcode( $...
The problem is that you're wrapping your <code> add_action() </code> calls inside of the conditionals, but at the point at which those <code> add_action() </code> calls are executed, neither the query nor the query conditionals are available yet. Solution: put the conditionals inside the callbacks : <code> function faq...
WordPress conditionals not working
wordpress
How can I turn a URL like: <code> http://site.com/?project=5 </code> into: <code> http://site.com/project/5/ </code> ? I was looking the rewrite doc here: http://codex.wordpress.org/Class_Reference/WP_Rewrite#Examples and came up with this <code> // Adding a new rule function my_insert_rewrite_rules( $rules ) { $newrul...
The PHP code is not enough, you need to edit your .htaccess file correspondingly. (You can do this with <code> $wp_rewrite-> mod_rewrite_rules(); </code> somehow, or edit it manually.) However, be aware that URL rewriting is complicated stuff - are you sure you need it? If you are using pretty permalinks for posts/page...
Help with url rewrite
wordpress
I'm sure this is a dup, but I honestly can't find an answer. I'd like to add a message to the start and end of my posts: <code> "Check out my new startup: Facebook For Dogs!" </code> Is there a simple way to do this, hopefully using a plugin?
You'll want to hook into <code> the_content </code> to add a message. Something like this: <code> &lt;?php add_filter('the_content', 'wpse51338_filter_content'); /* * Filter the content to add a message before and after it. */ function wpse51338_filter_content($content) { // not a singular post? just return the content...
How do I add a promotional message to my posts?
wordpress
I would like to track when a user changes their password. Is there a way to detect when a password has been changed?
WordPress sends an email to the admin's email when a user resets their password. To get a notification when a user changes their password you could hook into the <code> profile_update </code> action which is fired when a user's profile is updated. When the action is fired WordPress has already validated and updated the...
How can I detect if a user changes their password?
wordpress
I find myself using many of the same snippets of code for my <code> functions.php </code> file in new websites. Is there a method I can use to create a few different shared <code> functions.php </code> files to use across my websites? I am not referring to a WPMU installation, but completely separate installations of W...
If your functions can go in a single file (no images, or linked js/css files), you could add them to mu-plugin file. See the Must Use Plugins page on Codex for more information. EXAMPLE: <code> &lt;?php /* Plugin Name: CommonCodes Plugin URI: http://you.com/ Description: A common use file Version: 1.0 Author: You Autho...
Shared functions.php across multiple WordPress websites
wordpress
I want to list images for only user uploaded image. Here is the scenario: Using the image uploader on front end using iframe. I have added <code> upload_files </code> cap to subscriber level users and want them to see only images they uploaded. I've found this Q stackexchange-url ("Restricting Users to View Only Media ...
The media upload form that i was pulling up via thickbox was <code> media-upload.php </code> . So, i had to change the conditional to <code> if( 'upload.php' != $pagenow &amp;&amp; 'media-upload.php' != $pagenow) </code> . I forgot to look into the obvious place :) <code> // Code originally by @t31os add_action('pre_ge...
Media library to list images only user uploaded
wordpress
There's a function attached to a set of actions, like this: <code> add_action('some_tag', 'the_function'); function the_function($maybe_some_vars){ // ... } </code> Is it possible to find out the action name ("some_tag") within the_function? The reason I'm asking, is that I'm attaching the function to multiple actions ...
Simple: <code> current_filter(); </code> ( link to plugin.php ) or <code> global $wp_current_filter; </code> .
Getting the action's tag name within the action
wordpress
For a plugin that communicates with somewhere else, I hear we're supposed to use wp_remote_post and wp_remote_get instead of PHP's Curl library . Okay, but is there a fast and proper way on plugin execution to test for a blog's PHP/host OS to have the proper transport mechanism installed? I mean, I could attempt a test...
I wouldn't cause the plugin to die like that. Just check for cURL each time you need to make a call or fall back on <code> wp_remote_(post|get) </code> (eg. write a wrapper function that takes care of the check and send the data/headers you want). BUT, if you really really want to disable the plugin if cURL is not inst...
On Plugin Activation, How Do I Check for Proper Transport Mechanism?
wordpress
Disabling this WordPress feature which automatically generates various sizes of an uploaded image, is normally as simple as going to WordPress Dashboard > Settings > Media screen and changing all image-size options to <code> 0 </code> (zero). Unless I am missing something, this is not the case with my blog. Any image I...
Take a look at the output of <code> get_intermediate_image_sizes() </code> . If there are any image sizes listed other than <code> 'thumbnail' </code> , <code> 'medium' </code> or <code> 'large' </code> , a plugin or a theme has added a custom size. From our chat discussion I know it was WPtouch Pro . :) But it could h...
Why are extra 92 pixel square thumbnails created?
wordpress
I added a Meta Box Like So: <code> add_action('add_meta_boxes', function() { add_meta_box('CNMeta', 'Custom MetaBox', 'CNCustomMeta', 'post'); }); </code> I also added a thing that saves all of the meta information like this: <code> add_action('save_post', function($id) { if(isset($_POST['CNPrice']) ) { update_post_met...
To update a post. <code> &lt;input id="publish" class="button-primary" type="submit" value="Update" accesskey="p" tabindex="5" name="save"&gt; </code>
Add a Save Button to Custom Meta Box
wordpress
Is it possible to create taxonomies based on theme settings? That is, are theme settings actions run before taxonomies / post types are initialized?
Yes. Post types and taxonomies are (should be) registered on the <code> init </code> hook. You are able to use <code> get_option </code> inside that hook to retrieve your theme's settings and register your post type/taxonomy with args based on those settings. (By the way post types and taxonomies are really plug-in ter...
Create WordPress taxonomies based on theme settings
wordpress
I want to create a simple reservation (reservation.php) form for a custom content type (houses), i have created the reservation.php in the theme directory. The question is: How can i link to this general reservation form from the custom post type and pass the post id via <code> POST </code> or <code> GET </code> , so i...
If you have to make it a separate page that's available by visiting a permalink, you have to think what happens when user visits this page directly, without visiting the single post (house) first. If you know how to handle it, the easiest way would be to make the reservations.php it's own page template and just link to...
Set generic reservation form for custom post type
wordpress
I'm using the following code to produce a <code> wp_editor </code> instance: <code> &lt;?php if (version_compare($wp_version, "3.3") &gt;= 0) { ?&gt; &lt;p&gt;&lt;?php wp_editor( $answer-&gt;post_content, 'answer', array( 'media_buttons' =&gt; true, 'wpautop' =&gt; true ) ); ?&gt;&lt;/p&gt; &lt;?php } else { ?&gt; &lt;...
Use <code> the_content() </code> not <code> echo get_the_content(); </code> . As you can see in <code> wp-includes/default-filters.php </code> <code> wpautop </code> is added for the filter <code> 'the_content' </code> which is called in <code> the_content() </code> .
wp_editor not adding paragraphs despite wpautop being set to true
wordpress
I'm trying to insert some CSS at the very top of the Current Theme Stylesheet via plugin. (So that the CSS is easily over-ridden by the plugin user). How would you prepend CSS to the Theme Stylesheet? Also i'm trying to put some Javascript just before the /body tag in the theme, how would that be accomplished?
You should never modify the current theme's stylesheet via a plugin. What if the theme gets updated, or the user changes themes? Not a good idea. Instead, you should have the plugin create a custom css file, which could be located anywhere you wish, even inside of the current theme's folder. The only way to output info...
How to output CSS to the beginning of the stylesheet in a Wordpress Plugin
wordpress
I have a custom taxonomy "stat groups" (non-hierarchical) for my custom post type "stats". I created a link on the edit page for the chosen stat group term on the edit page for a stat. After clicking the link and submitting the changes to that term, wp redirects to the edit-tags.php but without the post type in the que...
Got it! I'm not sure exactly what the culprit was, but I did a few things that resulted in it working. Here's a summary of the code I used: I defined this helper function based on code found in <code> redirect_cannonical() </code> <code> function get_current_url() { $current_url = is_ssl() ? 'https://' : 'http://'; $cu...
redirecting improperly after updating custom taxonomy term when referring from CPT edit page
wordpress
I'm trying to add some CSS to the head part of the CSS but I can't get it to work (I want to add it to the head before the Theme CSS so the plugin user can easily over-ride plugins default CSS without !important over-rides). Here is what I tried: <code> &lt;?php add_action('wp_head', 'addCSS'); function addCSS() { wp_r...
You don't call enqueue or register functions hooking into the <code> wp_head </code> hook. At that hook its too late to add more, I guess, unless you play with priority parameter. Use the init hook to call <code> wp_enqueue_* </code> &amp; <code> wp_register_* </code> functions. Do it like this: <code> &lt;?php add_act...
Can't get CSS Into the Head via add_action
wordpress
I need to select all posts from database without fetching some categories. For example I fetch posts with this code: <code> $featuredPosts = new WP_Query(); $featuredPosts-&gt;query('showposts=40'); </code> So, now, how can i remove categories with id of: 22, 23 and 24?
Make query like this: <code> $query = new WP_Query( array( 'posts_per_page' =&gt; -1, 'category__not_in' =&gt; array( 2, 6 ) ) ); </code> 2, 6 being the category ID you want to exclude.
How to remove specific categories from posts?
wordpress
I have a wordpress site. I have a div that I only want to appear on the homepage (in the header). What type of php if statement do i need... In other words: only show .... in the header of the main blog index page. Problem is the header itself is loaded in every page. Thanks!
See: http://codex.wordpress.org/Function_Reference/is_home <code> &lt;?php if(is_home()): ?&gt; &lt;div&gt;Your div.&lt;/div&gt; &lt;?php endif; ?&gt; </code>
Only show div on homepage/blog index in wordpress/php
wordpress
When I first began looking into this, File Gallery got me much closer to solving the problem. The only issue is that the plugin only displays the generic non-image icon when I upload a file. Does anyone know of a pre-existing plugin that would either work alongside File Gallery or in place of it to achieve logos specif...
WordPress has a native function <code> wp_mime_type_icon() </code> in <code> wp-includes/post.php </code> that you can use. Basic example: <code> // $attachment should be a full post object if ( wp_attachment_is_image( $attachment-&gt;ID ) ) { echo wp_get_attachment_image( $attachment-&gt;ID, array( 480, 900 ), FALSE, ...
Looking to display non-image files in Gallery with logo specific to file type
wordpress
I have single post templates in a folder in my child theme marked "single". I need the sub categories to use the same template as their parent. I've read a dozen tutorials all of which were more than 3 years old and don't seem to work anymore. So what's the correct way to do this? Here's what I was trying. <code> funct...
You should try and use the WordPress hierarchy instead of <code> singe-cat- </code> . Make your parent category template using <code> category.php </code> or <code> category-{slug}.php </code> , and then use the technique here, http://codex.wordpress.org/User:MichaelH/MyPlugins . Or for more options try this plugin, ht...
Use template of parent category for single post sub-categories
wordpress
I'm using the well-written Oenology theme by Chip Bennett as the Parent to my own Child theme. In my development process, I've discovered that there are some challenges for people writing Child themes when it comes to controlling styles. I've just discovered that my main style.css file gets loaded before every other st...
Just FYI, this question probably borders on too localized , as it is specific to the Oenology Theme. That said, here's where I think you're having a problem: Oenology enqueues two style sheets: <code> style.css </code> , directly in the document head (thus before <code> wp_head() </code> is fired) <code> {varietal}.css...
how do I queue my Child stylesheet/s *after* every Parent stylesheet/statement?
wordpress
I need to be able to get all posts in the blog that were published in between two dates. The get_posts() API call doesn't seem to provide a method for limiting the time period of the returned results to a particular date range. If this isn't available, how could this be done through direct queries. I've attempted to do...
There are two ways to do this, both involve <code> WP_Query </code> . No Hooks Unfortunately, this is the less flexible way of doing things, but it is the way which is built into <code> WP_Query </code> . With the default <code> WP_Query </code> time parameters, you can get all the posts for a given numerical date. For...
How to fetch all posts in a category that were published between two given dates?
wordpress
When I try to use <code> get_page() </code> function I get the error message: <code> Only variables can be passed by reference </code> &nbsp; But what doesn't make sense is that I can use a work around that blows my mind: First test <code> $test1 = get_page(49); </code> Returns error message <code> Only variables can b...
Correct to your first test: <code> $id = 49; $test = get_page( $id ); </code>
get_page() - Only variables can be passed by reference
wordpress
I'm writing a plugin and am trying to figure out how to add data to the end of a post based on some Custom Meta Information. So i've done this so far: <code> add_filter('the_content', 'AppendMeta'); </code> And here is the "AppendMeta" function <code> AppendMeta($content) { echo $content; // Echo out post content $Pers...
Nevermind, found out I can use <code> get_the_ID(); </code> . This function will return the post id inside the <code> the_content </code> filter. The function simply declares the global <code> $post </code> object and returns its ID. <code> add_filter('the_content', 'wpse51205_content') wpse51205_content($content) { ec...
How to get Post ID with the Add Filter Function
wordpress
I currently have a custom field added to my attachment's form called <code> artist_credit </code> using the hook <code> attachment_fields_to_edit </code> . When a person enters a name into the artist credit field, I want it to (if it hasn't got the tag already) assign a tag with that name to the attachment's tags when ...
I managed to make it work but not fully. First, the code you provided is not retrieving an already saved post_meta. I based my code in the introductory code of this tutorial: http://wpengineer.com/2076/add-custom-field-attachment-in-wordpress/ And am using the regular post_tag taxonomy instead of a custom one. And, las...
Set attachment tags from attachment's custom field data
wordpress
I'm having a problem retrieving post_meta values that I have stored in an array. I use this for storing the array: <code> add_action( 'comment_post', 'add_food', 1 ); function add_food(){ global $post; $testvalues = array('bread', 'cake'); update_post_meta($post-&gt;ID, 'food', $testvalues); } </code> and this for retr...
Aha! I think I found your answer. Two facts: The description of the $meta_value argument on add_post_meta() functions's codex page notes: An array will be serialized into a string. The $single argument's description on the get_post_meta() function's codex page notes: If set to true then the function will return a singl...
Retrieving multiple values to the Post Meta (using an array)
wordpress
I would like to change the behavior of one function in a plugin. Instead of rewriting the file and having to deal with updates I would prefer a solution that works similar to the way add_filter works for the wordpress core. Is this possible using either php or wordpress?
If there are hooks in the function, this is possible, if not, there may be pluggable functions, where you can replace their function with your own custom function. I have not seen pluggables in plugins frequently, but with most of the more popular plugins, you do see actions and filters. You may be able to interact wit...
Overide a function that is inside a plugin
wordpress
The theme that I'm developing is basically a portfolio, where the projects are custom post type and they are divided in categories (custom taxonomies). Here is how I'm defining both: <code> $labels = array( 'name' =&gt; _x('My Portfolio', 'post type general name'), 'singular_name' =&gt; _x('Portfolio Item', 'post type ...
It seems from the OPs answer that the problem was not to do with the template, but using an incorrect url. To get the link of a taxonomy term you can use <code> get_term_link() </code> : <code> &lt;a href="&lt;?php echo get_term_link($term,'product_category')?&gt;"&gt;&lt;?php echo $term-&gt;name; ?&gt;&lt;/a&gt; </cod...
Template for custom post with custom taxonomy
wordpress
I'm trying to set up theme options so they save with AJAX, I found this tutorial http://return-true.com/2010/01/using-ajax-in-your-wordpress-theme-admin/ it's calling <code> $options = get_option('test_theme'); </code> but I don't understand what that is returning. it calls this right before the form, presumably to loo...
This sets $options to the value of test_theme in the database, you can go to phpmyadmin and the wp database and the wp_options (if wp is your prefix) and do a search on option_id row and you'll find it there. To get this option it should be saved before in the database using add_option() and update_option() , for more ...
what does $options = get_option('test_theme'); do?
wordpress
I am having a problem which I didn't meet before. I took a client website for just a small bunch of modifications, so I wasn't there when WordPress was installed or when the theme was developed. But when I enter the admin area, I can not upload media, I can not edit slugs, and on top of all, the "edit" screen for pages...
I had the same problem, but some extra and different plugins, after 2 days of disabling plugins one by one, checking theme files etc, etc, I decide to start from 0, Backup database, (all post, etc,~) and just re install. Not a beauty, but it will solve the problem faster than you searching for the needle on the haystac...
Whole bunch of errors on WP website - media upload, edit slugs, edit screen not working
wordpress
(This is sort of a follow-up to stackexchange-url ("this question").) I'm able to display the two WYSIWYG editors on my theme options page, but the values I enter into the editors aren't saved. I've read a ton of stuff about the Settings API and wp_editor() in hopes of making this work in the most WordPress-friendly wa...
You need to add a name attribute to your editors. The name attribute needs to be set to the value of of your option, so like this: <code> function us_partners_cb() { $us_partners_desc = get_option( 'us_partners_desc' ); echo wp_editor( $us_partners_desc, 'uspartnersdesc', array('textarea_name' =&gt; 'us_partners_desc')...
wp_editor() fields on Theme Options Page not saving
wordpress
I'm using the <code> trash_post </code> hook to set a flag in a custom table to indicate that this item is "deleted", but when the user chooses to restore that post, what hook can I use for that? I couldn't find anything on this page https://codex.wordpress.org/Plugin_API/Action_Reference , but maybe there's another wa...
Looking at the code for WP 3.3.2, it seems that <code> trash_post </code> is actually <code> wp_trash_post </code> . From the <code> wp_trash_post() </code> function in <code> /wp-includes/post.php </code> : <code> do_action('wp_trash_post', $post_id); add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status'...
Is there a recover_post hook to go with trash_post hook?
wordpress
I have a feed link http://www.wdcdn.net/rss/presentation/library/client/iowa/id/128b053b916ea1f7f20233e8a26bc45d and I have to read all the elements of feed including credits, here is how the feed is displayed <code> &lt;item&gt; &lt;title&gt; &lt;![CDATA[Dave&amp;#39;s Lawnmower Bish Bash]]&gt; &lt;/title&gt; &lt;link...
WordPress bundles and wraps SimplePie class for feed download, caching and processing. Retrieving namespaced data with it would be something like this: <code> $feed = fetch_feed( 'http://www.wdcdn.net/rss/presentation/library/client/iowa/id/128b053b916ea1f7f20233e8a26bc45d' ); $items = $feed-&gt;get_items(); foreach ( ...
How to read the xml file in wordpress?
wordpress
I have been doing some cleaning up in the database of one of my WordPress installs, and I noticed that the <code> wp_options </code> table was about 2.1mb, and had 1200 rows. I've gotten it down to around 800 rows, and 1.2mb. However, there are a bunch of transients. Should I remove these? I know they don't autoload, s...
This is not an amount that is likely to cause performance issues. However if you are concerned about leftover transients it is worth looking into if any code you are using is consistently "leaking" them (creating transients that are never removed). See stackexchange-url ("Are transients garbage collected?") for relevan...
Should I remove transients from the wp_options table?
wordpress
I've a hard time googling for this issue. On my blog , whenever I update an existing page, code sections are doubly escaped. I.e., on a recent page I have <code> find /V "QWERTYUIOPPO" &lt; calc.exe:yourads.txt </code> and after a recent edit it has become: <code> find /V &amp;quot;QWERTYUIOPPO&amp;quot; &amp;lt; calc....
I face this issue quite often on my own site where I publish code tutorials. Unfortunately, there isn't a good solution. Instead, I recommend this workflow: Use the WYSIWYG editor to build your article content leaving placeholders for your code snippets. Switch to the HTML editor to add your code snippets The visual ed...
When I re-save a post with [code] sections, the entities are double-escaped (> becomes &gt; etc)
wordpress
I want to add a logout button on the side admin menu (because I disable the admin bar for the users). So I thought add_menu_page() is the way to do it, but how to add the link to the regarded function? Here is what i did: <code> add_action( 'admin_menu', 'my_logout_menu' ); function my_logout_menu() { add_menu_page( 'L...
I'm using this as a custom logout button, it also displays a random quote before logout the user. I think you can adapt it to your needs by removing what you don't need. Instructions: Copy the code below and save as users-logout.php Create a folder called users-logout, upload the file and the images below to work. Any ...
add logout button on admin side menu
wordpress
I am trying to dynamically get the facebook php sdk from my current themes folder. I am writing this in my functions.php, but all my attempts break the site. See my attempts below... <code> require template_url('/') . 'facebook-php-sdk-6c82b3f/src/facebook.php'; require get_bloginfo('template_url') . 'facebook-php-sdk-...
Use <code> get_template_directory() </code> instead , require doesn't work with http://
Require file in functions from theme directory using PHP
wordpress
I'm building a site with several different post types (blog posts, products, informational articles, etc.). On archive type pages (search results, tag pages, etc.), I want to display content from the different post types in visually distinct sections. Then, the user could either select the specific page we he wants, or...
I would do multiple queries. I know that generally that slows stuff down, but sometimes if you're looking a page with a ton of content, it's to be expected.
Help Structuring Query for Archive Pages
wordpress
I have a doubt on changing my permlink structure for the second time. What happened was I have moved my old website to the wordpress blog by copying all the posts. After the migration, i have set the 301 redirect to the new url of wordpress and now it is updated in the google. After that I found the permlink is not goo...
You can check the status of the redirect using any number of developer tools (chrome can do this by default). I believe the default redirect that wordpress does when the post title is changed is a 301, but I could be mistaken. If you need finer control (or would like regex support), the Redirection plugin is a great op...
Changing the permlink and SEO
wordpress
I've gone through a few of the other similar topics but any of the solutions won't work for me. Basically I only want to show an if the custom field has had information added into it. Here's my code, even if you don't give me an answer could you point me in the correct direction as to how to do this. <code> &lt;div cla...
This is really more of a PHP question than a WordPress question. But, based on this example code: <code> &lt;li&gt;&lt;a href="http://&lt;?php echo the_field('helpline_url'); ?&gt;" class="tiptip web" title="&lt;?php echo the_field('helpline_url'); ?&gt;" target="_blank"&gt;&lt;?php echo the_field('helpline_url'); ?&gt...
Only show when content added via custom field
wordpress
I'm having problems with what I think are conflicting plugins. I've done my research and I'm a bit stuck. This conflict only seems to happen a little while after a core or a plugin update. Not immediately, but often around 12 hours later. What happens is the backend stops responding, whilst the front end appears to wor...
Does your file-server have an error log in the WP Directory? I would start by turning on the DeBug and error reporting via the wp-config file. Open your wp-config and add this from the WordPress Codex Debugging page if it's not already there: <code> // Enable WP_DEBUG mode define('WP_DEBUG', true); // Enable Debug logg...
Diagnosing plugin conflicts
wordpress
Is there a way to migrate all comments on my blog over to Disqus somehow? Thinking about using Disqus rather than the regular WordPress comments, but I don't want to lose the comments that are already written.
During the process of installing the Disqus Comment System plugin on WordPress, it actually allows you to export your comments to Disqus, as shown in the screenshot above. And they've quite a helpful documentation as well: Install Disqus on WordPress (self-hosted) Exporting comments from WordPress to Disqus Not to ment...
Migrate comments to Disqus
wordpress
This may seem like a silly question but I cannot figure this out. I've created a variable in my functions.php - and I'm trying to echo it in my template files. I'm guessing it's because of scope. What's the simpliest what to echo a variable or create a function to allow me to output this facebook ID in various template...
If you don't have access to the value, it's likely a scope issue. Make sure you globalize it first: <code> &lt;?php global $fb_app_id; echo $fb_app_id; ?&gt; </code> Alternatively I'm not a fan of global variables, so the alternative I recommend is using WordPress' built-in filter mechanism. You add the filter in your ...
get php variable from functions php and echo it in theme template files
wordpress
I want to do some action at the time of deleting a category using that category id. Is it possible to get the category id?
Use the <code> delete_category </code> action, which passes category id as an argument: <code> function my_category_delete_function( $id ){ // do something with category $id } add_action( 'delete_category', 'my_category_delete_function', 10, 1 ); </code>
How to get the deleted category id?
wordpress
Does anybody know predefined (suggested by WP) CSS classes which should I use in my theme? I have seen somewhere in Internet a list of all CSS classes, which are used in WP theme, but can't find it. UPDATE: I have found the site where I've seen this list: http://www.wpbeginner.com/wp-themes/default-wordpress-generated-...
There are many CSS classes generated by WordPress, depending on context. The Theme Review Guidelines include the following, WordPress-generated CSS classes: Alignment Classes: .aligncenter .alignleft .alignright Caption Related Classes: .wp-caption .wp-caption-text .gallery-caption Post Classes: .sticky Comment Classes...
CSS classes for theme
wordpress
I have a weird bug on the dashboard: the dashboard says there are a total of 3 posts, but the list is empty and says "No posts found" (see image below) It's a fresh install on a shared Windows hosting, using SQL Server as the database with the WP Db Abstraction plugin . I tried reinstalling WP completely and the bug is...
Try the fix posted here: http://sourceforge.net/tracker/?func=detail&amp;aid=3485384&amp;group_id=315685&amp;atid=1328061 It worked for me. translations.php line 726 Change this: $pattern = '/LIMIT\s*(\d+)((\s*,?\s*)(\d+) )(;{0,1})$/is'; to this: $pattern = '/LIMIT\s (\d+)((\s*,?\s*)(\d+)*);{0,1}$/is'; Removing the ext...
Dashboard says "no posts found" even though there are some posts
wordpress
stackexchange-url ("I'm following some of the other people's advice here") about adding my js file before the closing body tag but it doesn't seem to work for me. If someone would be so kind as to check this for me please? <code> &lt;?php /*load the js file into the footer*/ function myscript() { if( wp_script_is( 'jqu...
You should always add javascript (and styles) with the Wordpress function <code> wp_enqueue_script() </code> Works like this: <code> wp_enqueue_script( $handle // the name of your enqueued file, in your case 'myscript' ,$src // source of your file, can be external, or for your example: get_bloginfo('template_directory'...
How to add javascript just before the closing body tag in the footer of WordPress
wordpress
For some reason my RSS feed is repeating the site title twice without a space, obviously quite annoying. BlognameBlogname for example. Is there any hook i can use to have a custom title for the RSS Feed? So i could have a title 'This is My RSS Feed for Blogname' or anything i wanted? Is this possible or am i stuck with...
Edited : Bad answer removed. Here is the working code: <code> function custom_blogname_rss($val, $show) { if( 'name' == $show ) $out = 'Custom Blog Name'; else $out = $val; return $out; } add_filter('bloginfo_rss','custom_blogname_rss', 10, 2); </code> Don't forget to change Custom Blog Name to something useful. Put th...
RSS Feed Custom Title?
wordpress
I am running a fresh install of Wordpress 3.3.2 and the only plugin enabled is one I'm developing, but I can't seem to get past a permissions issue in <code> add_menu_page </code> . With the exception of using anonymous functions instead of named functions, I'm following the documentation almost exactly. My plugin sour...
You want the <code> admin_menu </code> hook, rather than <code> admin_init </code> . Also, you shouldn't use anonymous functions. Instead, use: <code> function wpse51004_add_menu_page() { add_menu_page('Some Page', 'Some Page', 'manage_options', 'some-slug', 'wpse51004_some_page_callback'); }; add_action('admin_menu', ...
add_menu_page permissions - what am I doing wrong?
wordpress
I'm looking to create a site with a wide array of user contributed content. I have strong experience in programming, and I'm evaluating Wordpress for the task. My question: Having created a custom post type, can I allow a broad array of users (not necessarily per-approved or know to me) to create and manage their own i...
Right - so there are some plugins that do this. Some are focused on saving admins the trip to the backend. I needed something that kept users out of the backend entirely, but allowed them to contribute custom posts. I'm going with wp-user-frontend and so far, it's doing the trick.
Allowing logged in users to create custom posts
wordpress
I'm working with <code> wp_dropdown_pages() </code> and <code> wp_dropdown_categories() </code> and both are always outputting a <code> &lt;select&gt; </code> -box with its <code> &lt;option&gt; </code> s as items. Is it possible to add a filter/hook to this funtions so I get just the <code> &lt;option&gt; </code> s wi...
A filter called <code> wp_dropdown_pages </code> exists in the <code> wp_dropdown_pages() </code> function. That filter allows you to modify the output of the function. However, for the thing you want to do I would not recommend using this filter since this will apply to all code that calls <code> wp_dropdown_pages() <...
Add filter to wp_dropdown_pages() or wp_dropdown_categories() - no select container?
wordpress
I'm using the postMash plugin to allow a client to be able to easily reorder posts without having to change the timestamp on each one, and it works fine. However, I'm using a custom loop to call the latest posts in a category onto the home page like so: <code> $i=0; $events = get_posts( array ( 'category' =&gt; 6, 'ord...
That plugin is 3 years old. I'm not sure if it uses the menu_order column to set the order but if it does you can filter pre_get_posts or your custom query with: <code> 'orderby' =&gt; 'menu_order', 'order' =&gt; 'ASC' </code> This would all have to be done before the $post object is added to the $events array so it wo...
How do i use postMash to order posts in a custom loop?
wordpress
I am looking for a wordpress plugin where I can upload images and store them into a category. For example I would have say..10 images to upload, I would give the album a name or date and then upload them. Is there any plugins around that can do this?
Sounds like NextGen Gallery would be a good fit - http://wordpress.org/extend/plugins/nextgen-gallery/
Wordpress Image uploads plugin needed
wordpress
I have found some code to display all posts in a page but it's not exactly what I need. What I need to do is for example: <code> &lt;h1&gt;This is the Title&lt;/h1&gt; &lt;p&gt;This is the content of the posts. It displays part of the content only. User need to click the More! link below to view the whole post.&lt;/p&g...
That's because the code you listed only includes a reference for the title and the link. Here's your original code, annotated ... Original <code> &lt;?php $debut = 0; //The first article to be displayed ?&gt; &lt;?php while(have_posts()) : the_post(); ?&gt; &lt;!-- Display the title of the current page that's listing y...
Display all posts in a page code for template
wordpress
I came across this page http://flare.bringthepixel.com/pages/services/ and on it there is this message: "The entire code of this sample page is available in the Shortcode Generator". Lets say i gave someone this theme and wanted to produce his/her own page look just like the one shown without inserting one shortcode af...
If you are going to use that shortcode inside post/page content, then you can build any layout/design with that shortcode. You can do even more if you are calling <code> do_shortcode() </code> in your theme. Technically its possible to do it and whether it would be a good implementation or not depends on the use case. ...
Using shortcodes to communicate my page design
wordpress
With add_action, I want to intercept as early as I can in my plugin and send a 304 Not Modified header per some rules. Does anyone know what the order is of events? When I view this page , it seems to hint that the best place for this would be plugins_loaded, and that it comes before the init event. Is that correct? Th...
The page you referenced does have the correct order of events listed there. If you want to see which events were fired for a particular request you can install debug-bar and debug-bar-action-hooks. If you are wanting to send a header either <code> plugins_loaded </code> or <code> init </code> will work. But it is recom...
How Do I Load My Action Earlier Enough?
wordpress
I am working on a website and need the fallowing functionality: From the admin area, I need to be able to add/remove/edit codes/tokens that I will later send out to people so they can come to my site and use them to register a user. I just do not want people to be able to register to my site without a code that I will ...
There are several plugins around that allow you to customize your registration process. One such plugin is called Pie Register . Among the many features it offers, it allows: Invitation Codes Is your blog super exclusive? If so, you better require an invite to join your high end crew. Setup multiple codes and track whe...
registration plugin
wordpress
How can I connect to the database using the wp-config.php file ? I'm trying to make a script more Wordpress friendly, and I need to connect to the database, but without installing the script as a plugin. Basically I have on my script <code> $host = "xxxxxxxxxxx"; //database location $user = "xxxxxxxxxxx"; //database us...
Using the defines the user sets in wp-config: <code> mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); </code> EDIT : Since your script is outside the Wordpress environment, what you want to do is initiate it before using the defines in wp-config. <code> require_once(path/to/wp-config.php'); mysql_connect(DB_HOST, DB_USER,...
Connect to database using wordpress wp-config file
wordpress
How do you create %post_type%/%postname%/ permalink structure? This is what is not working: eg. ( domain.com/blog/ ) -> "click on post" -> ( domain.com/post-name ) How do I make "blog post" permalinks work like this... eg. ( domain.com/blog/ ) -> "click on post" -> ( domain.com/ blog /post-name ) Although other custom ...
Beyond the fact that disabling 'pretty' permalinks in the Settings > Permalink page disables pretty permalinks for all post types and taxonomies, the options do not effect custom post types or taxonomies. If you set the permalinks to <code> blog/%postname% </code> then your posts will have the structure: <code> www.you...
How do you create %post_type%/%postname%/ permalink structure?
wordpress
This is an extension of stackexchange-url ("this question/answer"). A comment on that question references that <code> template_include </code> is preferred to <code> template_redirect </code> when loading templates from a plug-in. However, hanging this to template_include is breaking everything on the site (any other p...
So the <code> template_redirect </code> is used for things such as canonicalisation, feeds etc. If you want to alter the template that is served <code> template_include </code> is preferred. Unlike <code> template_redirect </code> , <code> template_include </code> is a filter which filters the path of the template page...
template_include (overriding default plugin templates via current theme)
wordpress
I an using two taxonomies with private posts. category e.g. massage, travel location e.g. new-york-city, boston etc. On a location page, I want to show categories that are relevant to that location. e.g. If I am on <code> ?location=boston </code> page I would find all the posts that are in <code> boston </code> , then ...
In <code> the_loop </code> , just add this code... <code> &lt;?php $cats = wp_get_object_terms(get_the_id(), 'category'); ?&gt; </code> Print_r <code> $cats </code> , it will have the list of the <code> categories </code> applied to this post.
Showing relevant categories on custom taxonomy template
wordpress
I'm trying to get permalinks working with custom taxonomies and custom post types. Following the instructions stackexchange-url ("here") I was able to get it almost working, but one small glitch. The code to register the taxonomy looks like this: <code> $args = array( 'labels' =&gt; $labels, 'public' =&gt; true, 'show_...
Ok, I managed to get it working by hooking into the 'request' filter, then checking to see if the last segment is term or not. If it's not, change the $request var: <code> function alter_the_query( $request ) { $dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars $dummy_query-&gt;parse_...
Help with hierarchical custom taxonomies and permalinks...almost there
wordpress
This is what I'd like to accomplish, hopefully under one WP install: I would like to use one WP install for my main domain + three subdomains, where subdomains need to be somehow "masked" / add-ons of other domains. i.e. www.mymaindomain.com branch1.mymaindomain.com -> www.differentdomain.com branch2.mymaindomain.com -...
You need the following: 1) Enable WordPress Multisite in your main domain The Ultimate WordPress Multi Site Network Management Guide (tutorial) Multisite Rationale (case study, tips, tools) 2) Install the plugin WordPress MU Domain Mapping Multisite Domain Mapping Tutorial Here's a workaround to make Domain Mapping wor...
Multiple domain names under one Wordpress Installation
wordpress
This seems trivial but I can't get it to work. Here's my code: <code> $args = array( 'numberposts' =&gt; -1, 'eventcategory' =&gt; 'nice-events', 'post_type' =&gt; 'event', 'post_status' =&gt; 'publish' ); var_dump(get_posts($args)); </code> As you can see, my taxonomy is <code> eventcategory </code> and the term is <c...
You cannot make up your own arguments - rather than replacing the <code> 'category' </code> argument with your taxonomy name, use <code> 'tax_query' </code> . See "taxonomy parameters" section of the codex on get_posts . <code> $args = array( 'post_type' =&gt; 'event', 'post_status' =&gt; 'publish', 'tax_query' =&gt; a...
How to query custom post type by term?
wordpress
What is the best way of linking to WordPress pages with PHP? Considering that I move the page from a local server to a live server to another URL? <code> &lt;a href="/wordpress/services" title="Read More" class="yellowButton"&gt;Read more&lt;/a&gt; </code> How could you replace this code with PHP linking to the WordPre...
Page Permalink from $id If you know the Page <code> $id </code> , use <code> get_permalink() </code> : <code> &lt;?php $permalink = get_permalink( $id ); ?&gt; </code> Page Permalink from $slug If you know the Page <code> $slug </code> , such as <code> /about </code> (including hierarchy, such as <code> /about/work </c...
Internal Links to Pages in PHP?
wordpress
Building off of stackexchange-url ("this question/answer"), I've sucessfully implemented the <code> single </code> view for my custom post types, but I'd also like to offer the same thing for taxonomies. I've looked through the docs and thought that is_taxonomy() would be perfect for filtering out exactly what taxonomy...
This is what I ended up using (for all those interested): <code> function override_tax_template($template){ // is a specific custom taxonomy being shown? $taxonomy_array = array('tax1','tax2'); foreach ($taxonomy_array as $taxonomy_single) { if ( is_tax($taxonomy_single) ) { if(file_exists(trailingslashit(get_styleshee...
Default taxonomy template in plugin, override in theme
wordpress