question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I use a custom post type in one of my sites for image slideshows. I have publicly queryable set to false/off but when Google crawls my site I see 404 errors for the URLs for my slideshows. I thought that by having publicly queryable off Wordpress would not create those front end URLs. How can I completely turn off the ...
Another option would be to set a 301 redirect for all the slideshow CPTs to redirect somewhere (like the home page). This would get picked up by Google, and also make sure no one accidentally gets on them <code> function rkv_slideshow_redirect() { global $wp_query; // redirect from 'slideshow' CPT to home page if ( is_...
How to set a custom post type to not show up on the front end
wordpress
I an trying to enqueue four script files and keep getting this error: <code> Fatal error: Allowed memory size of 103809024 bytes exhausted ... wp-includes/class.wp-dependencies.php on line 175. </code> I used wp_register_script like this: <code> wp_register_script( 'sat-ba-cond', $scriptsrc . 'jquery.ba-cond.min.js', a...
The problem is the de-registering the core-bundled version of jQuery, and re-registering using your own, arbitrary version. Do not de-register core-bundled versions of scripts ( especially jQuery) in order to register arbitrary/custom versions of those scripts. Doing so can and will cause breakage and unintended conseq...
Fatal error: allowed memory size when after using enqueue_script
wordpress
I need to query the database on add_action( 'init', '...') to find post ids with the field 'product_discount_option' set to true. I know at least one of my product posts have the field 'product_discount_option' set to true. However when i run the SQL query below and var_dump it outputs an empty array , array(0) { } .. ...
Thanks for your help s_ha_dum, I had a look at the table structure using phpMyAdmin, ACF Plugin saves fields to the postmeta table, so sb_wpsc_meta needed to be changed to sb_postmeta. also needed to change what was being SELECT to post_id aswell as the meta_value to 1. final query; <code> "SELECT post_id FROM sb_postm...
SQL query - get ids - Advanced Custom Fields / WPeC
wordpress
Is it possible to show the Biographical Info textfield while creating a new user? I know it's possible to add user bio by editing a user AFTER it has been created. But I would like to do this while creating the user.
No. There are no hooks or filters to add an input field to the create user form. Maybe it is possible to add an input field via jQuery. I have not tested it. If it is pssible to add an input field, than it should be possible to save this information because the process of creating an user is the same as updating an exi...
Show Biographical Info while creating new user
wordpress
I mean, for what I remember of my english classes it should be <code> WordPress' </code> , or not? Would this be a stackexchange-url ("Meta Question")? Or a stackexchange-url ("English Language &amp; Usage") one? [update] What I ended up writing (in an email) before Comments and Answers was ...deal with a couple of Wor...
WordPress is a singular without plural. A second instance would be a fork that could not use the same name, because the name WordPress is a trademark of the WordPress Foundation. Like Jesus , just more rules. If WordPress had a plural it would be WordPresses, like in mess or mistress . But the prerequisite for that wou...
What is the Plural of WordPress?
wordpress
I want to ask that is there a way display all my custom taxonomies in a drop down menu with checkboxes so when the user check any taxonomy it will be slected and when the user click the submit button .the new post will be created with selected custom taxonomy. i know how to insert it in new post but i WANT TO KNOW ABOU...
To list the options for a custom taxonomy you need to query the taxonomy terms. To do that you use <code> get_terms() </code> http://codex.wordpress.org/Function_Reference/get_terms <code> // We are assuming color is the name of the taxonomy $colors = get_terms( 'color', array( 'orderby' =&gt; 'name', 'hide_empty' =&gt...
Making a form for user to add new custom post with custom taxonomies and custom fields
wordpress
I have my own widget, that uses WP_Widget class, and executes its code inside function in this class. Is there any ways to run this widget using shortcode inside post? This is how my widget structure looks like: add_action( 'widgets_init', 'register_my_widget' ); function register_my_widget() {} class My_Widget extends...
I think you are out of luck as wordpress core doesn't have this kind of functionality. Quick googling shows that there are plugins to do that like this one http://wordpress.org/extend/plugins/amr-shortcode-any-widget/ , but if you have programming skills you should probably write a shortcode handler with/instead of the...
How the widget can be run by shortcode
wordpress
I want to get the GROUP_creator_id when an user joins any GROUP. So if I got the <code> group_id </code> after immediately performing the the <code> groups_join_group </code> action by <code> add_action() </code> method.
<code> $group_id </code> is the first argument passed to <code> groups_join_group </code> action hook function, the second argument is <code> $user_id </code> . You can use these data to obtain group <code> creator_id </code> like: <code> add_action('groups_join_group', 'my_groups_join_group_action', 10, 2); function m...
How to get the group_id from the "groups_join_group" action in buddypress
wordpress
I'm working on a setup for which I need general users to be able to edit a specific list of pages, but not create any new ones. Looking through the Codex , I don't see anything that will come close to this desired functionality, but I thought I might be looking through it. Failing a pre-set, I started looking into Adva...
In WordPress 3.5 there will be a new capability <code> create_posts </code> . You could create a new user role or change the role <code> editor </code> and stackexchange-url ("remove that capability") for this role.
Is there an existing capability to allow editing of only pre-existing pages? If not, a good way to implement this?
wordpress
How can you check if specific username is logged in?
<code> wp_get_current_user </code> then compare the object that's returned <code> user_login </code> proprety with the specific username you'd like to check against. <code> &lt;?php add_action('admin_init', 'wpse74389_check_username'); function wpse74389_check_username() { $user = wp_get_current_user(); if($user &amp;&...
Check if specific username is logged in
wordpress
Is there an easy way to reverse the default item order of a category rss feed? <code> Default: Last posted item first Wanted: First posted item first </code> No plugins please, plain wp api function calls (such as add_action or add_filter) will do!
You can simply reorder you RSS Feed via the GET parameter <code> ?order=ASC </code> or <code> ?order=DESC </code> after your FEED url!
Reversing the order of items in a category rss feed?
wordpress
I have registered a custom post type 'Clients' and a taxonomy for this post type for categorizing posts. There are currently 3 categories for a Client: 'Logo Project', 'Video Project' and 'Web Design' project. Some Clients may belong to multiple categories. On the Edit Page for a Clients post, I have a Flexible field l...
Okay, the following code should do the trick for you: <code> function get_clients_correct_template($single_template) { global $post; if ( 'clients' == $post-&gt;post_type ) { $_template = false; // Get all the terms for this post $categories = wp_get_post_terms( $post-&gt;ID, 'clients_categories' ); if ( $categories &a...
Wordpress - Creating multiple versions of the same single-customtype.php depending on selected taxonomy categories
wordpress
I have a plugin that is returning post IDs based on <code> $_GET </code> data (which searches a secondary DB table). I am attempting to hook into the standard <code> have_posts() </code> function called within a taxonomy page to show the results. Since the data is passed in on the actual page, I can't use the normal <c...
I can see several possibilities for this one. First, I am not convinced that that you can't use <code> pre_get_posts </code> though maybe you'd have to reorganize your code. You don't have to wait for your theme template to use <code> $_GET </code> . Try: <code> function tst() { // global $_GET; // sometimes necessary ...
Modify WP Query post__in before have_posts()
wordpress
I have created custom template page like this with a custom query on page showing only details fetch from my custom table not any post. <code> /* Template Name:product */ &lt;?php get_header(); ?&gt; &lt;?php $data = $wpdb-&gt;get_results("myquery Here"); foreach($data as $row) { product Name: $row-&gt;p_name; prod pri...
<code> &lt;?php /* Template Name:product */ get_header(); // check if product_id is not set or is empty string if( !isset($_GET['product_id']) || '' == $_GET['product_id'] ) { // if so, run your query and display data $data = $wpdb-&gt;get_results("myquery Here"); foreach($data as $row) { echo '&lt;div&gt;'; echo '&lt;...
How to set up conditionals in page templates?
wordpress
I would like to programatically remove some meta boxes when a user is editing a specific page in the admin. The page itself is using a template (tpl-about.php). I know I can remove all meta boxes from all pages with this function: <code> function remove_post_meta_boxes() { if(!current_user_can('administrator')) { remov...
Those are 2 different things: Hide only in one Page Hide only when Page uses a specific template Case 1 - in this example the Page ID is <code> 3 </code> , but note that the removals are for <code> page </code> and <code> post </code> alike: <code> add_action( 'admin_menu', 'remove_post_meta_boxes' ); function remove_p...
Remove metabox from specific page template in admin
wordpress
I'm trying to get all the children categories to display in this loop but I'm struggling with the code. This is what I have so far. <code> &lt;?php $args=array('orderby' =&gt; 'name', 'order' =&gt; 'ASC'); $categories=get_categories($args); foreach ($categories as $cat) { ?&gt; &lt;dt&gt;&lt;a href="#" class="customer-...
You can't just pass the string "parent" to <code> get_categories </code> . You have to pass the ID of the parent. <code> $categories=get_categories( array( 'parent' =&gt; $cat-&gt;cat_ID ) ); </code> Notice that there are two similar but not equal "get child" parameters that you can use. child_of (integer) Display all ...
Get the children of the parent category
wordpress
Hello WordPress Answers! I'm having trouble with the widget <code> update </code> function saving values correctly, but first let me explain the situation. I'm writing a simple news ticker widget plugin, which filters the posts displayed by post type with check boxes in the widget settings form. To generate the check b...
This took a bit to sort out. :) You are trying to use <code> $instance['post_types'] </code> in your <code> update() </code> function but are not setting that value at all in the form. I altered a couple of things so that the two match up. Leaving your form (mostly) as it is, your <code> update() </code> needs to be......
Widget update function not saving values
wordpress
under Settings-> Reading I can set which page should appear immediately when visiting my site as "home-page". In my case I want the archive of my custom-post-type named "events" as home/front-page of my site. So I have a hardcoded item in my navigation that says "Events" that links to /events and uses my custom-post-te...
I would do this: Create template and include events archive file <code> &lt;?php /* Template Name: Index Events */ get_template_part( 'category-events' ); // Archive for Events (category-events.php) ?&gt; </code> Then create page using this template and finally select this page in Settings -> Reading
Set a hard-coded page-template (post-type-archive) as home/front-page of my wordpress blog?
wordpress
I'm struggling to figure out how to use wp_handle_upload() with ajax when processing a form. What I'm doing here is using a form to allow users to edit posts from the front end so they can do some things like change the image for a post so we'll start there. I'm gonna leave out chunks of this function to keep it simple...
Uploading files in ajax is a bit tricky because it is not possible to upload files using the browser's XMLHttpRequest object so you need to use some kind of Ajax upload plugin. Also <code> wp_handle_upload() </code> is not what your using in your code its <code> media_handle_sideload() </code> <code> wp_handle_upload()...
Using wp_handle_upload and media_handle_sideload with ajax
wordpress
I have the following function. This is part of a membership-based site. When a post of the type "message" is moved to Publish status, it should send an email to all users who belong (custom user meta) to the district(s) that are checked (taxonomy) when the post is drafted. If I send to a small group, it seems to work. ...
Well, this isn't a full solution per se, but I would start by isolating whether the problem is the SQL queries or the <code> wp_mail() </code> call. If you comment out the <code> wp_mail() </code> line, you can get an idea of how long the function takes to run the queries and build the messages without trying to send t...
wp_mail function timing out
wordpress
The admin bar suddenly disappeared from the front end side of my site. It is present and works alright at the backend. I thought it could be due to some plugin so I deactivated them one by one and checked . Now all the plugins are deactivated and the admin bar is still missing...My theme does have the <code> wp_footer(...
Might be one of 3 things (since you verified a wp_footer) you set it to not show in your user profile a plugin you installed has a Confliction with it you created a php / js code which produces errors in your wp_footer Course of action: 1. Check you personal user profile backend to see you haven't turned it off 1. turn...
WP admin bar disappeared
wordpress
There is a theme hack or a worm circulating online which adds this code to all functions.php files. It happened to me on my local server. Here's the code - http://pastebin.com/AUsHUng1 How do I find the theme hack that creates it? Or the worm? UPDATE: I have found that this line: <code> $elem == substr(__FILE__,-13)){ ...
THIS IS MY FINAL SOLUTION: Clean all the malicious code (see my PasteBin link above) from all functions.php files (best to check globally using a text editor like Notepad++) and you're done. Check all downloaded themes for the code in functions.php file. There are more themes infected with this code online. Also edited...
How to remove the automated code posted in functions.php?
wordpress
I'm developing a Wordpress blog for a client who needs to embed their own video files. Flash video was our format of choice until recently, but is there a preferred format for Wordpress? One that easily integrates?
The Codex lists several core-supported oEmbed sites (including a few being added in 3.5): YouTube (only public videos and playlists - "unlisted" and "private" videos will not embed) Vimeo (note older versions of WP have issues with https embeds, just remove the s from the https to fix) DailyMotion blip.tv Flickr (both ...
Preferred Wordpress video format?
wordpress
I have a loop of posts and I allow a user to edit each post using ajax. When the edit button is clicked for the post I use ajax to retrieve the template part containing the edit form for the post. Easy enough to do by creating a function with 'get_template_part' and then localizing a script where I use $ajax to execute...
Sidestep the entire issue and just include fo_edit_script in the header of the page, rather than in the AJAX part. There's no need at all to do this. You might think that by only including it when its needed your optimising but your not, because it's having to load it every time you open an edit form. I'd go as far to ...
How to localize inline script called with ajax
wordpress
I've added a shortcode button in the TinyMCE editor in the page/post pages that opens up a Thickbox form. The button is working; it opens up the thickbox form like it should. However my stumbling point is getting the value BACK to the TinyMCE editor and closing the thickbox. This is the code I'm using to display the bu...
Okay so I spit through some existing themes I have to try and figure out how to achieve this. If anyone is reading this, this is how I did it: In the onclick function of the TinyMCE I called the ajax form and then inside the form I added some javascript that uses the <code> tinyMCE.activeEditor.execCommand('mceInsertCo...
Pass data back to TinyMCE from Thickbox
wordpress
I need to get logged in user id inside my plugin. Is this the proper way? <code> $root = dirname(dirname(dirname(dirname(__FILE__)))); if (file_exists($root.'/wp-load.php')) { require_once($root.'/wp-load.php'); } $user_id = get_current_user_id(); </code> Otto saying that we shouldn't load wp-load.php file since we hav...
If you're inside a plugin, WordPress is already loaded. You don't need to load it yourself. Inside whatever function needs the user ID, you need to do two things: Globalize the user data variable Populate the user data variable Here's some pseudocode: <code> function some_function_that_needs_user_info() { global $curre...
What is the proper way to get logged in user id in a plugin?
wordpress
I have added a new (small) image size to the theme we develop: <code> add_image_size('small', 160, 91, TRUE); </code> How to automatically generate these small images (exactly of the specified size) for every image uploaded in the past?
WordPress doesn't regenerate the newly registered size, only applies it to future uploads. You'll have to use something like the Regenerate Thumbnails plugin or one of the similar ones available at WordPress.org.
Auto resize images after adding a new size
wordpress
I want to pull four random images from the current post's attachments to display as "featured images". Therefor I am using the following function: <code> function fs_gallery_featured_thumbs( $post_id ) { // DEBUG: validate parent post ID echo $post_id; // Query to get images for this post $query = array( 'post_parent' ...
hat I do: in my template that I use to display posts within the standard loop, I make a call to above function: <code> fs_gallery_featured_thumbs( $post-&gt;ID ) </code> (originally I used <code> the_ID() </code> instead of <code> $post-&gt;ID </code> which gave me trouble. I guess bescause <code> the_ID() </code> actu...
get_children() returns ALL attachments instead only those attached to 'post_parent'
wordpress
The function below is used to show certain content after the first paragraph. I would like to show 'content X' after the 1st paragraph and 'content Y' after 2nd paragraph. <code> &lt;?php $paragraphAfter= 1; //display after the first paragraph $content = apply_filters('the_content', get_the_content()); $content = explo...
My way to do this ( see update below ): <code> function addParagraphs($content) { // you can add as many as you want: $additions = array( '&lt;p&gt;After 1st paragraph&lt;/p&gt;', '&lt;p&gt;After 2nd paragraph&lt;/p&gt;' ); $content = get_the_content(); $output = ''; // define variable to avoid PHP warnings $parts = ex...
Show content after the first and second paragraph
wordpress
Can someone tell me how to wrap the Read More anchor (that displays after an excerpt) with DIV tags using <code> get_the_content('Read More') </code> ?
Put a filter on <code> the_content_more_link </code> . Untested but... <code> function wrap_more_link($more) { return '&lt;div&gt;'.$more.'&lt;/div&gt;'; } add_filter('the_content_more_link','wrap_more_link'); </code>
How to wrap "Read More" link in a DIV tag?
wordpress
I have a custom post type events and am displaying these events using archive-events.php and single-events.php from the template hierarchy. I have a custom query in archive-events.php <code> $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $events_query = new WP_Query( array ( 'post_type' =&gt; 'events...
You probably need a filter on <code> get_{$adjacent}_post_join </code> and <code> get_{$adjacent}_post_sort </code> to get those to work. Apologies, but I don't have time right now to work up the actual filters and debug them, but maybe that will get you started.
Make Next and Previous on single-$posttype.php use the same order as archive-$posttype.php
wordpress
I'm using have_fields to loop through an array and create a list of checkboxes. Everything seems to be working great, except that the checkboxes aren't consistently showing as "checked" on the backend. Here's the code I'm using: <code> &lt;?php $items = array( 'bio', 'youtube', 'articles', 'learn-more', 'testimonials',...
After more searching I decided to try one of the alternative methods listed in the checkbox-meta.php example file. I used a "foreach" loop instead of the "while" loop and the checkbox state is now loading properly. Here's the updated code: <code> &lt;?php foreach ($items as $i =&gt; $item): ?&gt; &lt;?php $mb-&gt;the_f...
WPAlchemy - Checkboxes not saving
wordpress
I'm creating custom post types with Magic Fields v2.0.1 and i use the qTranslate v2.5.32 plugin for a second language on Wordpress 3.4.2. The problem is that on Magic Fields in the settings of the custom post type when i select to support only "Title" (and not "Editor") there is no extra Post tile field for the transla...
I solved the problem by checking the option Editor on the Magic fields post type settings and hiding the visual editor with an extra option on Adminimize settings targeting the Visual Editor with it's ID on the specific post type. So now qTranslate can see the Title and apply the second language while the visual editor...
MF2 and qTranslate problem with custom post types post titles
wordpress
I am using Wordpress media uploader to upload images and I was wondering if there is a way to make it upload to my remote server instead of my local server? Example: My wordpress blog is hosted on Server A and I want to want to use the media uploader to upload images to Server B instead of Server A. Both servers run Ub...
I have just built a plugin that does this. It is not perfect but it do its job. You can find it in my Github: https://github.com/pontusab/wp-ftp-media-library So you need to change some things within the file on the row 28: <code> /** * Change this to match your server * You only need to change the those with (*) * If ...
Upload images to remote server
wordpress
I'm trying to speed up a wordpress site -- this site: http://richardclunan.net I'm following the observations here: http://gtmetrix.com/reports/richardclunan.net/9ps7Zc0j The first item says: "The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for th...
Keeping the answer within the wordpress realm, your best bet is to install W3TC and use that plugin to optimize your speed. Even with the default settings you'd already be gaining a lot. If you want to delve further you can keep tweaking the settings within the plugin. The next step to take would be setting up (with th...
How to specify expiration of cacheable resources?
wordpress
I want to use wp_editor(); (custom editor) I've tried several methods but I am lost and I can't get it to save the post and retrieve the content in template stackexchange-url ("How to edit posts with the new wp_editor api?") also <code> add_action( 'edit_page_form', 'my_second_editor' ); function my_second_editor() { /...
You would need to add a metabox and then add the wp_editor as a field. You'll then need to process/save the meta data before you ever get to the part where display the data. I just did this this morning with the Types plugin , which is about the easiest thing that I've found. ( Advanced Custom Fields and Metabox are al...
How to use wp_editor(); in functions.php then retrieve content in the template
wordpress
I'm taking a look at s2member -- I have it running, and my site is very slow -- it's taking on average about 9 or 10 seconds to load. This is the site: http://richardclunan.net I want to figure out if the s2member plugin is causing it to be slow. And whether there are other faster membership plugins... 3 questions: Are...
If you disable a plugin (don't delete it), the settings should be preserved for when you reactivate it. s2member and other membership plugins are pretty complicated and may cause performance issues... especially if you are on shared hosting or a host that severely limits the # of simultaneous database queries. If you m...
Affect on speed of wordpress membership plugins -- currently trying s2member
wordpress
I'm developing my first theme for woocommerce. I need to be able to have "authors" (really "designers") assigned to woocommerce products. Is that feasible? I was thinking of using the wordpress built-in "author" user, but the interface of a product editing does not provide the "author" box, unlike a "post" editing inte...
Simply use <code> add_post_type_support </code> : <code> add_action('init', 'wpse_74054_add_author_woocommerce', 999 ); function wpse_74054_add_author_woocommerce() { add_post_type_support( 'product', 'author' ); } </code> User assigned with custom role Authors enabled in Products post type Another option, which I'm no...
Woocommerce: assign an "author" to a product
wordpress
I am trying to retrieve all posts from an rss feed from a category, and I have working code that does this. However, on one category I will only get all posts until a certain date. Any post prior to this date will not show up. I have debugged this by posting a new article and set it as close to the last retrieved post ...
Ok I finally found the answer. The issue was caused by a strange enclosures from the podcasting plugin. Removed the enclosure and BAM everything is fine now! The main think to notice: if you have such a problem, your feed is probably invalid. Validate your feed first and then see if there are any problems there!
date issue with category post retrival
wordpress
I have the following code inside my single.php page: UPDATED CODE <code> &lt;?php if (have_posts()) : the_post(); $post_id = get_the_ID(); if ( is_single() ) { $cats = get_the_category(); $cat = $cats[0]; } else { // category archives $cat = get_category( get_query_var( 'cat' ) ); } $cat_id = $cat-&gt;cat_ID; $cat_name...
Your problem is that you're using <code> query_posts() </code> , when you need to be using <code> WP_Query() </code> . To display all posts (by ignoring pagination, use the <code> posts_per_page </code> parameter : <code> $cat_query_args = array( // Include posts from category with ID $cat_id 'cat' =&gt; $cat_id, // In...
Sidebar limiting to 10 posts?
wordpress
I have a page.php and single.php template that are 100% identical. Yet, when I render page.php the div don't get nested in the same way as single.php and the layout gets broken. I've even diff'd the output of the two pages and, with the exception of the meta and non visible elements, they are also 100% identical. Follo...
Edit Based on this comment: commenting out comments_template works. The problem lies in the template markup in <code> comments.php </code> . The likely reason that you see it in some output and not others is likely because you've got comments enabled in one context, and not in the other. Try comparing single posts with...
Page.php vs Single.php
wordpress
while writing new code and testing it, I incorporate it into my site by testing for the remote IP address as follows; i.e., I'm the only one who will see the new code: in <code> /functions.php </code> : <code> // to hide certain sections/features from people other than myself $myIP = '219.88.88.88'; // the value as cur...
Debug &amp; Caching ...simply doesn't work. If you'd load a page (on a cached request) and doing all those funky things like checking if you're logged in, if you're using an administrator -role account, etc. than all this would be bypassed by the caching plugin. The cache gets applied to the resulting HTML page, not th...
server load. $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_HOST']
wordpress
i am wondering how i go about making a Template for some of my pages to use a different sidebar? I have created the widget like this: <code> register_sidebar(array( 'id' =&gt; 'ourPat-sidebar', 'name' =&gt; 'ourPat Sidebar', 'before_widget' =&gt; '&lt;div class="widget %2$s" id="%1$s"&gt;', 'after_widget' =&gt; '&lt;/d...
In order to accomplish this you will need to also create a separate page template to use. You may need to double check your template head information. Example: <code> &lt;?php /* * Template Name: Your Template name */ ?&gt; </code> This has to be put at the top of the page template. Then within the custom page template...
Custom page sidebar using Template dropdown box
wordpress
I am working on a small community style website for my family to use. Mainly it is a small version of a social network so my nieces and nephews can have fun with each other. I have set up "freinding" functionality and it works fine. But when I respond to a friend request an additional ajax function is fired. My AJAX fu...
After a little digging I found that the method I used for handling my email notifications was receiving the user ID as a string. As soon as I cast it as an integer all my notifications started sending. So the additional AJAX function that was firing had no affect on my notification email being sent.
An adiitional function fires on my AJAX submit
wordpress
What I'm trying to do is display the most recent post (a la my theme's "single.php") on my "home" page. This is complicated by the fact that I have certain plugins (specifically, Scripts n Styles) that are hooking wp_head and wp_enqueue_scripts. In these hooks, they are checking is_singular() to see if my per-post java...
stackexchange-url ("Chip's answer") helped me fix the error, but it took a bit more tweaking to get it fully solved. With a static front page, the <code> front-page.php </code> template will be called (as per the hierarchy ) with <code> $wp_query </code> populated with page ID that corresponds to the page you've chosen...
How do I display only the latest post on my home page, while maintaining proper plugin hooks?
wordpress
I've published a plugin on WP repository that allows some theming for Gravity Forms. This plugin as been tested with Twenty Ten, and Twenty Eleven. When I've tried to test it in a site that uses Thesis 1.8.5, I've found out that something wasn't working. What this plugin does is to extend the Gravity Forms shortcode wi...
Well, I've just realized that my client's theme was a custom version of Thesis with an incomprehensibly commented <code> wp_footer() </code> : as soon as I've uncommented it, the issue (obviously) disappeared.
plugin's script and style enqueing not working on Thesis
wordpress
I need to add conditional logic to purchases. ie – item a included for free with the purchase of item b or item a can be purchased individually for x amount . Does anyone know if this functionality can be achieved through settings on the backend of WPeC. Thanks Cam
There isn't an out of the box solution for this in WP e-commerce. But if your products are downloads you could simply add the file as a variation.
WPeC - Adding conditional logic to purchases
wordpress
I have a problem with a sidebar. I have 4 sidebars: "Essential", "Essential+", "Premier" and "Premier+". <code> register_sidebar( array( 'name' =&gt; __('Essential Plan'), 'before_widget' =&gt; '&lt;ul&gt;', 'after_widget' =&gt; '&lt;/ul&gt;', 'before_title' =&gt; '', 'after_title' =&gt; '' ) ); register_sidebar( array...
Try giving a unique ID to each dynamic sidebar, via the <code> id </code> parameter passed to <code> register_sidebar() </code> : <code> register_sidebar( array( 'id' =&gt; 'essential', 'name' =&gt; __('Essential Plan'), 'before_widget' =&gt; '', 'after_widget' =&gt; '', 'before_title' =&gt; '', 'after_title' =&gt; '' ...
duplicate sidebar
wordpress
I use various custom image sizes (by <code> add_image_size </code> ) and I have set my JPEG compression to 30% with this filter: <code> function jpeg_quality_callback($arg) { return (int)30; } add_filter('jpeg_quality', 'jpeg_quality_callback'); </code> If I am not mistaken, the above code compresses all of my custom i...
The <code> 'jpeg_quality' </code> filter hook functions accept two arguments: <code> $jpeg_quality </code> and <code> $function </code> which is the function from within the filter hook is fired and can be either <code> image_resize </code> or <code> wp_crop_image </code> . So there is no way to selectively set the qua...
Set JPEG compression for specific custom image sizes
wordpress
I have a function called <code> function getSingleAmazonProduct($asin='') </code> . It returns an amazon product. I have a form field to enter the <code> $asin </code> . <code> &lt;div id="asinform"&gt; &lt;form id="productpreview" action="#"&gt; &lt;input type="text" id="asin" name="asin" value="" placeholder="Enter A...
<code> &lt;div id="asinform"&gt; &lt;form id="productpreview" action="#"&gt; &lt;input type="text" id="asin" name="asin" value="" placeholder="Enter ASIN"/&gt; &lt;input type="hidden" name="asin_form_post" value="1"/&gt; &lt;input type="submit" value="Preview"/&gt; &lt;/div&gt; &lt;div id="asinpreview"&gt; &lt;!-- Prev...
Execute a function using ajax
wordpress
I am trying to fetch all direct children of a page. But I am getting all children and grand children as well. Any ideas? PHP Source: <code> $args = array( 'child_of' =&gt; $post-&gt;ID, 'parent ' =&gt; $post-&gt;ID, 'hierarchical' =&gt; 0, 'sort_column' =&gt; 'menu_order', 'sort_order' =&gt; 'asc' ); $mypages = get_pag...
Please check the parameter 'parent'. It seems there is a space after the name.
Getting only direct child pages in WordPress with get_pages
wordpress
I have a query for a custom post type: <code> &lt;?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $books = new WP_Query(array( 'post_type' =&gt; 'wiki', 'posts_per_page' =&gt; '50', 'paged' =&gt; $paged )); ?&gt; </code> And i want to loop through these posts using the loop-books.php: <code> &lt;?p...
You will either need to globalize <code> $books </code> (if you want to stick to <code> get_template_part() </code> ) or use <code> require( locate_template( 'loop-books.php' ) ); </code> instead of <code> get_template_part( 'loop', 'books' ); </code> . This issue is caused by <code> $books </code> in <code> loop-books...
Using a custom WP_Query with get_template_part loop
wordpress
I'm writing a plugin to do some specific business logic - edit records for authenticated users, etc. Rather than having the overhead of a form processing plugin that uses stuff in template tags. I've created a rewrite do redirect like: <code> /mylisting/909 -&gt;/wp-content/themes/myplugin/edit.php?id=909 </code> Which...
I've created a rewrite do redirect like: <code> /mylisting/909 -&gt;/wp-content/themes/myplugin/edit.php?id=909 </code> Which seems to make sense as I'm keeping the very specific logic to an individual plugin. There is a better way: stackexchange-url ("Create an endpoint"), use your code in a callback handler for the n...
How can I use get header from within my plugin?
wordpress
This problem only occurs with the articles/blog posts on the homepage of the site, readbuzz.com . On the homepage of the site, the author's name is supposed to link to that particular author's post page, where all the blog posts the author posted on the website will show up. Instead, each name that shows up links to th...
The code below is the correct code, in several different PHP files. Currently need to know how to write it using the the_author_posts_link(); <code> &lt;p class="postAuthor"&gt;By &lt;a href="&lt;?php the_author_meta('user_url'); ?&gt;"&gt;&lt;?php the_author(); ?&gt;&lt;/a&gt;&lt;/p&gt; </code> Just replace this: <cod...
Authors' Links on Homepage Not Going to Author Post Pages
wordpress
I am trying to find out where the header menu links on my WP is located so that i can change the URL of the page. the link is: http://blahblah.com/?page_id=11 and i need to change it to: http://blahblah.com/?page_id=36 However, i do not see anywhere in the menus that i have to change that link. I even looked into the m...
Note that you're using a Custom Nav Menu, meaning that the contents of the menu can be customized . The easiest solution is simply to: remove the current "Our Doctors" page from the menu add your desired page to the menu edit the menu item to change the displayed title to "Our Doctors" save the menu
Page header menu links change
wordpress
Problem I have a user based site, so when user deletes his profile somehow his/her comments stay visible. There is no name and blank avatar with the comment. Is there any way to delete the comments of a user if the user deletes his/her profile and how? Is there a function of somehow? This really is a strange problem.
+1 @toscho 's comment. This will break nested comment / conversation in comment. You should disable nested comments in the Settings. Try this code. Note that this is not tested <code> add_action( 'delete_user', 'my_delete_user'); function my_delete_user($user_id) { $user = get_user_by('id', $user_id); // delete comment...
Remove the deleted user comment
wordpress
I use a lot of embedded videos (via <code> oembed </code> ) on my blog, and that can slow down page loads. Is there a way to automatically replace YouTube (and other) videos with a thumbnail (preferably the post's featured image). And then replace the thumbnail with the video iframe when clicked?
Notes Solution for YouTube and Vimeo. Uses Featured Image or default thumbnail from video provider. If more than one oEmbed exists in the same page, using the Featured Image provoques duplicate "thumbs". Post has to be updated before changes are seen. To do: <code> &lt;iframe&gt; </code> and <code> &lt;img&gt; </code> ...
How to Replace YouTube Videos with a "Click to Play" Thumbnail?
wordpress
How can I sort posts ascending by post title for a specific post type, but on a category archive template? My schema involves a "video" custom post type and multiple subcategories of the aforementioned post type. I am using the Custom Content Type Manager plugin . How can I implement this?
You can use <code> pre_get_posts </code> to hook in and change the query. The argument passed to <code> pre_get_posts </code> is the query object. It fires for every query, so you need to check some things first. Quick example (not-tested) -- change the order on only the video type's post type archive page. <code> &lt;...
How can I sort posts ascending by post title for a specific post type, but on a category archive template?
wordpress
I am trying to convert this code to use the $wpdb. <code> $data = array(); $query = "SELECT * FROM videos"; $query_exec = mysql_query($query) or die(); while($row = mysql_fetch_array($query_exec)) { if ( $row['video'] == "http://youtu.be/".end(explode('http://youtu.be/',$row['video'])) ) { $data[$row['id']] = end(explo...
<code> wpdb </code> 's <code> get_results </code> method takes an optional second argument that let's you specify out the data is return the default is an object. But you can also set it to... OBJECT - result will be output as a numerically indexed array of row objects. OBJECT_K - result will be output as an associativ...
Fetch array with $wpdb
wordpress
I have a custom post type "Kalender_item" with a custom Date Field (YYMMDD). I want to list all the posts on a page sorted by Year and Month. For example: November 2012 (all events that occure in November 2012) December 2012 (all events that occure in December 2012) And so on... I have succeeded in ordering them like s...
This should get you started: <code> &lt;?php $the_query = new WP_Query( array( 'post_type' =&gt; 'kalender_item', 'post_status' =&gt; 'publish', 'meta_key' =&gt; 'kalender_item_datum', 'orderby' =&gt; 'meta_value' ) ); # This will hold what group we're in $current_header = ''; # The Loop while ( $the_query-&gt;have_pos...
How to List Events by Year and Month Using Advanced Custom Fields?
wordpress
I have a CPT called campsites and in there I have different categories ie. derbyshire, staffordshire, nottinghamshire etc. What I want to do is that when you click on a category eg. derbyshire, ideally I'd like it to say at the top of the page Campsites in derbyshire. Please help.
From what I understand, you just need to use this in your template as it sounds like you will be using an archive page for a given CPT. <code> &lt;h1&gt;&lt;?php post_type_archive_title(); ?&gt;&lt;/h1&gt; </code> I've not been able to test this but you can find more info about the options on this Wordpress Codex page....
How To Get Custom Post Type Category Title
wordpress
I have a custom post type with comments enabled. The comments metabox in the admin only appears when the post is published. I'm wanting to use the comments system as more of a discussion between certain authors (it will be hidden on the front end) so I would like the commenting system to be active when the posts are dr...
The following enables the default meta box for <code> draft </code> and <code> pending </code> posts (in the <code> portfolio </code> <code> post_type </code> ): <code> add_action( 'admin_init', 'wpse_74018_enable_draft_comments' ); /** * Add Comments Meta Box if CPT is 'draft' or 'pending' */ function wpse_74018_enabl...
How to enable comments for pending and draft posts?
wordpress
Usually, if I want to check for some attribute of the post I'm about to publish, I will check like this: <code> $post_title = $_POST['post_title']; </code> post_title is the name of the title field in the edit window. I thought I'd apply the same logic to the taxonomy meta box. <code> $formats = $_POST['tax_input[forma...
You're on the right track. When you do something like this in a form.. <code> &lt;input name="tax_input[formats][]" /&gt; </code> You create levels in the <code> $_POST </code> array. So you'd get the formats array like this... <code> &lt;?php $formats = $_POST['tax_input']['formats']; </code> Full example... <code> &l...
get_terms on save_post hook
wordpress
I am building a theme, and in the options I have created a place for link color. I cant seem to get this into the theme in any reasonable way. The best I can do is to put it after <code> wp_head </code> ... but that doesn't seem right. The color will be a hex color so I cant just set up style sheets for a fixed number ...
You would simply call that option inside of a callback, and hook it into <code> wp_print_styles </code> or <code> wp_head </code> (either one is semantically correct in this case). First, set up your callback, which will print an inline style sheet : <code> function wpse74013_print_custom_styles() { ?&gt; &lt;style typ...
How do I use a color from theme options?
wordpress
I'm using this code to display a page within my front page. I would like to learn how to add a div / spacer to isolate the page title... If I try to add a div class within the php code then it throws errors. Question: How can I add a div to the title within this bit of code? <code> &lt;div class="frontpage"&gt; &lt;?ph...
Try to change heading from <code> echo '&lt;h3&gt;'. $page_data-&gt;post_title .'&lt;/h3&gt;'; </code> like <code> echo '&lt;div class="class-name"&gt;'. $page_data-&gt;post_title .'&lt;/div&gt;'; </code>
Enclose title within a div?
wordpress
I have tried to create a function that generate a random slug when a post is created. I am a bit worried that the function generates non unique strings as slugs. How can I solve this? The function looks like: <code> add_filter('name_save_pre','unique_slug', 0); function random_string() { $length = 6; $characters = "012...
I've found this plugin that should do the trick: http://wordpress.org/extend/plugins/wp-hashed-ids/
how to automatically generate random slug
wordpress
This is in reference to stackexchange-url ("another answer") here on wordpress.stackexchange. The answerer used the filename as the hook to enqueue scripts and styles to certain pages. <code> add_action( 'admin_print_scripts-post-new.php', 'portfolio_admin_script', 11 ); add_action( 'admin_print_scripts-post.php', 'por...
The short answer is 'yes'. Taken from this article the suffix of those 'screen specific hooks' is given by: For custom admin pages added via <code> add_menu_page() </code> - including settings pages - (and related functions) it is the screen ID (the value returned by <code> add_menu_page() </code> ) For the admin page ...
Do WordPress Core Filenames Work as Hooks?
wordpress
I am trying to force publish 'future' or 'scheduled' posts, and I am having trouble The reason I am asking is because I am creating a site that allows users to do the editing on the front of the site, so I need a button that will allow users to force publish scheduled posts. Right now I am just trying to find a process...
I've done it. Here is the post with answers on publishing a post marked as scheduled. Been running the code for 2 years on the site in question and it's reliable. stackexchange-url ("Marking future dated post as published")
Force Publish Future (Scheduled) Posts Immediately
wordpress
Hey all i am wondering what i need to add in order to have a different sidebar for a set page? I created a category for the page ( called PatientEdu ): And made sure the page was linked to the category: But it still seems to be using the other category sidebar (Which i also do not know where its at)? So any help would ...
Register a new sidebar by pasting this into your theme's <code> functions.php </code> file: <code> register_sidebars( 'id' =&gt; 'patientedu' ); </code> Create a file called <code> sidebar-patientedu.php </code> and paste the following into it: <code> &lt;?php if (is_active_sidebar('patientedu')) : ?&gt; &lt;div id="si...
Sidebar links for different pages
wordpress
I'm trying to implement my own query ordering, here is what I came up with... <code> $query = new WP_Query('post_type=contentboxes&amp;include=' . $contentboxes . '&amp;order=ASC&amp;orderby=include' ); </code> My custom loop, $contentboxes looks like 34,45,23,46 with the orderby include argument. To implement my custo...
stackexchange-url ("Chain") the filters: <code> if ( 'include' == $query-&gt;query_vars['orderby'] ) add_filter( 'posts_orderby', /* … */ ); </code> And in your orderby filter use: <code> remove_filter( current_filter(), __FUNCTION__ ); </code>
Custom Order in WP Query
wordpress
I have a product search widget when you select certain products a hidden field is shown. I would like to set a custom category in my widget options that is then used for displaying my hidden field. I have the front end working 100% when I add the parent category_id manually to my code. Now I just need to set the catego...
I got it :-) thanks to stackexchange-url ("this") <code> function update( $new_instance, $old_instance ) { $instance = $old_instance; //Strip tags from title and name to remove HTML $instance['title'] = strip_tags( $new_instance['title'] ); $instance['kwtax'] = strip_tags( $new_instance['kwtax'] ); return $instance; } ...
Using wp_dropdown_categories in widget options
wordpress
In Drupal, you can assign a URI to a function that gets called, like this: <code> function mymodule_menu() { return array( 'custom_uri' =&gt; array( 'page callback' =&gt; 'my_custom_function', [...] ); ); } </code> This then tells Drupal to call the function <code> my_custom_function </code> whenever the url is <code> ...
Create an stackexchange-url ("endpoint"). That is a custom URL that will be handled by a callback. Examples are stackexchange-url ("How can I use WordPress functions in my stylesheet?") and stackexchange-url ("Is it possible to request several post types from a feed?"). See also <code> add_rewrite_endpoint() </code> an...
How to assign a Permalink to a Function
wordpress
Can someone tell me what's wrong with this function? <code> function xattachments_db_install() { global $wpdb; $xattachments_db_version = "1.0"; $table_name = $wpdb-&gt;prefix ."xattachments"; $sql = "CREATE TABLE IF NOT EXISTS ".$table_name. " ( 'xattachments_id' int(10) unsigned NOT NULL, 'xattachments_name' varchar(...
This part in your table creation SQL looks wrong: <code> DEFAULT CHARSET=CHARSET=utf8 </code> . It should just be <code> DEFAULT CHARSET=utf8 </code> . Also, <code> dbDelta() </code> is quite a delicate function. Don't ask me why, but you need to put a double space after the <code> PRIMARY KEY </code> keyword. You also...
Plugin: database creation
wordpress
I have three categories (news, pics, vids), but I have all of them showing up on my front page. I would just like the front page to have the news category (and possibly uncategorized category) to show. What is the best way to do this? Plugin? Or a piece of code on the front page?
Try adding this code to <code> functions.php </code> file: <code> add_action('pre_get_posts', 'ad_filter_categories'); function ad_filter_categories($query) { if ($query-&gt;is_main_query() &amp;&amp; is_home()) { $query-&gt;set('category_name','news, uncategorized'); } } </code> <code> category_name </code> is the slu...
Filter front page posts by category
wordpress
Just started playing around with Woocommerce, ran into a problem. I have a bunch of items (100+) and all of them only have a number as product title, 1,2,3 etc. The problem is that Woocommerce outputs the products like this: 1,11,12,13,14,15,16,17,18,19,2,20 – and so forth. How can I make it output correctly?
You'll either have to sort/order your products manually or create a custom sort order within WooCommerce. For that take a look at the WooCommerce docs and this snippet for doing just that. In this case you're also going to have to do a bit of MySQL manipulation as well so that you're sorting the numbers numerically. Se...
Sorting Woocommerce products with numeric titles
wordpress
I currently have the following trying to avoid showing tags (the icon in this case) when there aren't any, but the icon continues to show up. Any thoughts? <code> &lt;?php if ( is_singular() &amp;&amp; function_exists('the_tags') ) : ?&gt; &lt;p&gt;&lt;i class="icon-tags"&gt;&lt;/i&gt;&lt;?php the_tags('', ', ', ' '); ...
Get a string value for the tags and print it only if there are tags: <code> $tags = get_the_tag_list('', ', ', ' '); if ( "" !== trim( $tags ) ) { echo "&lt;p&gt;&lt;i class='icon-tags'&gt;&lt;/i&gt;$tags&lt;/p&gt;"; } </code>
How to not show tags if the post doesn't have any?
wordpress
I am creating a plugin in WordPress Version 3.4.2. When the administrator submits a form, a new folder is created inside my plugin directory and a file saved in this new folder. But it gives me the following error: <code> error : The file has not been created $dir = plugins_url()."/folder-name/; </code> The above code ...
Do not use the plugin directory to store new files. During an update the plugin directory will be erased by WordPress. And all files in it too. The plugin directory might be read-only in some setups (I do that always). Use the regular uploads directory for that. And <code> 0777 </code> is never a good idea. Write acces...
How to Create a Directory in a Plugin Folder?
wordpress
I'm building a plugin and I'm quite new to wordpress I have a class what has couple of methods what should execute database queries. The class look as it follows <code> class MyClass{ private $wpdb; function __construct(){ global $wpdb; } function query(){ $wpdb-&gt;query( $wpdb-&gt;prepare("INSERT INTO $wpdb-&gt;wp_co...
<code> class MyClass{ function __construct(){ global $wpdb; $this-&gt;db = $wpdb; } function query(){ return $this-&gt;db-&gt;query( $this-&gt;db-&gt;prepare("INSERT INTO {$this-&gt;db-&gt;wp_competitors} (id, ield_key, field_value) VALUES ( %d, %s, %s )", 1, $field_key, $field_value) ); } } </code>
queries inside of a class
wordpress
I created a hierarchical custom post type for a gallery. The parent pages are the galleries and the child pages are the albums. I want to display the most recent albums on my sidebar (so basically the most recent child pages). <code> 'post_parent' =&gt; 0 </code> I only find this in the codex, but this is the opposite ...
Assuming you know (or know how to get) the <code> $id </code> (as an integer ) of the parent post, use the <code> post_parent </code> parameter : <code> $albums = new WP_Query(array( 'post_type' =&gt; 'gallery', 'posts_per_page' =&gt; 6, 'post_parent' =&gt; $id )); </code> Edit Based on this comment: I don't know the p...
List the 5 most recent child pages
wordpress
I'm having a working nginx, php-fpm and other php packages and mysql. I've extracted wordpress-3.4.2.zip in /usr/local/nginx/html/blog. When I visit localhost/blog I get "500 internal server error". Is there any special configuration that needs to be done for nginx to make wordpress work?
Provided info by you is SO huge... so i can only advice. run nginx - it works? goto step 2 run nginx with php, see info.php with phpinfo() insie? goto step 3. run nginx with php and global host rewrite to this index script. It works ? go to step 4. run nginx with php and anabled error reporting (logs/display anything)....
How to configure nginx for wordpress
wordpress
When changing premalinks, none of the pages and links are not working except home page :( Result are shown below. Thanks in advance.
This is really a server question and not specific to WordPress. Be sure <code> mod_rewrite </code> is enabled in Apache on your version of OS X. Google that. Restart Apache after making changes to httpd.conf. You may also need to add a blank .htaccess file in the /Users/yourusername/Sites folder so that WordPress can w...
Wordpress custom permalinks not working on OS X localhost
wordpress
I'm trying to understand where to use filters and where to use actions. Suppose I have a query in a plugin, which later add on modules might modify to change the results of the query, thus modifying the arguments. Would this be an ideal implementation of this concept, or should I be using actions here? // Function to d...
+1 to both of the other answers, for explaining the primary differences between actions and filters . However, to answer your specific question, about which to use for modifying a query: Injecting your custom query into the template does , as you guessed, require hooking into an existing action . (Whether or not <code>...
When to use actions and when to use filters
wordpress
I'm trying to code a theme where I'll have a universal gallery page. Basically like: http://www.engadget.com/galleries/ However I'm at a loss for what I'd use to call all the galleries. I need the galleries to be custom post types (so I have domain.com/gallery/title-of-gallery/), but the galleries also have to be able ...
The underlying question here is How do I query all posts with image galleries? (since, once you have such a query, creating a custom template page to loop through them is fairly trivial). One method would be: Custom query of <code> attachment </code> posts with a <code> mime_type </code> of <code> image </code> Loop th...
How to make a page template to list all galleries?
wordpress
When I select a template for a page from the "Templates" selectbox, the selected item gets “value=selected” only after I hit save draft/publish/update. <code> &lt;option value='template-gallery.php' selected='selected'&gt;Gallery&lt;/option&gt; </code> How can the option receive the value “selected” without the need of...
This would have to be fully coded and tested, but I think the roadmap is: Deregister the Default Meta Box and Make a Custom One @MikeSchinkel answer to this question is very detailed and thoughtful: stackexchange-url ("Adding Page Attributes Metabox and Page Templates to the Posts Edit Page?") In that case, it is for d...
How to dynamically save a selected option from page "Templates" selectbox?
wordpress
This is the code I use to display all product categories with thumbnails: <code> &lt;?php $cats = get_terms('product_cat', array( 'hide_empty' =&gt; 0, 'orderby' =&gt; 'name' )); ?&gt; &lt;div class="container"&gt; &lt;?php foreach($cats as $cat) : ?&gt; &lt;?php global $wp_query; if($cat-&gt;category_parent == 0) { $c...
I found how to make this: <code> &lt;?php $taxonomy = 'product_cat'; $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $title = ''; $empty = 0; $args = array( 'taxonomy' =&gt; $taxonomy, 'orderby' =&gt; $orderby, 'show_count' =&g...
How to split the categories of subcategories with thumbnails
wordpress
I have the following basic page setup: xxx.net/ -> static homepage xxx.net/blog/ -> blog page with loop showing all posts xxx.net/gallery/ -> gallery page with loop only showing posts that are categorized as "gallery" xxx.net/extra/ -> another page with loop only showing posts that are categorized as "extra" The two sp...
One post cannot (and should not) have two single post URLs. All you can change is the archive view, the list of posts. If <code> /gallery/ </code> and <code> /extra/ </code> are post of the post type <code> page </code> , use a custom page template for those. Update stackexchange-url ("Create two endpoints") <code> gal...
Choose template depending on URL
wordpress
I've created a custom Taxonomy for a Custom Post Type, and created five or so terms within the taxonomy. I've created a single image upload and assigned it to the custom taxonomy, and uploaded images for each term. I can't for the life of me figure out how to get the image to display. I've var_dumped the term but there...
As per the plugin documentation : The second parameter needed is a string in the format “$type_$id”. <code> // get value from a taxonomy (taxonomy = "category", id = 3) $value = get_field('field_name', 'category_3'); // get value from a taxonomy (taxonomy = "events", id = 76) $value = get_field('field_name', 'events_76...
Custom Taxonomy Images with Advanced Custom Fields
wordpress
I have two questions in a row: How to check the array values, what <code> WP_Query </code> has brought to me? If I get 10 posts in cat=3, then I want to get only 5 from them, and then want to echo them individually wherever I want them to print. It may be like: ------------------- | 1 | 2 | ------------------- | 3 | 4 ...
Assuming you start with: <code> $custom_query_args = array( 'cat' =&gt; 10, 'post_per_page' =&gt; 5 ); $custom_query = new WP_Query(); </code> Then to answer your first question, you can see what is returned (for development/debugging) via: <code> var_dump( $custom_query ); </code> To output your query as a normal loop...
How to check the array values, what WP_Query has brought to me?
wordpress
is there any way to style the profile page on wordpress ? I will like to add something like: Start of the page just below the <code> &lt;h2&gt; </code> tag <code> &lt;div id="normal-sortables" class="meta-box-sortables ui-sortable"&gt; &lt;div id="poststuff" class="metabox-holder has-right-sidebar"&gt; &lt;div id="post...
It works on a standard profile page (your profile / Profile) without other plugins installed. Other plugins may affect the overall result. I think code can be improved, if some one knows how please give it a go. <code> function better_profile_page($buffer) { global $pagenow; if ($pagenow == 'profile.php' || $pagenow ==...
Custom style on profile options page
wordpress
I am working on this web . I need to fiugure it out on how to avoid repeating the URL in the home Page. The Home page has actually two url creativesquaresummercamp.com/ creativesquaresummercamp.com/welcome-to-your-best-summer/ I want my Home page just having this url creativesquaresummercamp.com This is happening of co...
From the comments: What are your settings under Dashboard -> Settings -> Reading. Specifically, what are your Front Page Displays, front page, and posts page settings? And your reply: exactly this is the point, the client has used a Theme called Choice and in the Theme Frontpage Settings there is this page selected :"W...
How to avoid duplicate Url for the home page
wordpress
<code> &lt;?php $custom_post_types = get_post_types( array( '_builtin' =&gt; false, 'public' =&gt; true ), 'objects' ); foreach ( $custom_post_types as $custom_post_type ) { $custom_post_type-&gt;permalink = get_post_type_archive_link( $custom_post_type-&gt;label ); } echo '&lt;ul&gt;'; foreach ( $custom_post_types as ...
<code> &lt;?php $custom_post_types = get_post_types( array( '_builtin' =&gt; false, 'public' =&gt; true ), 'objects' ); ksort( $custom_post_types, SORT_ASC ); echo '&lt;ul&gt;'; foreach ( $custom_post_types as $custom_post_type ) { $exclude = array( 'products', 'sales' ); if( TRUE === in_array( $custom_post_type-&gt;na...
Exclude custom post type from list
wordpress
I've two wp sites (multisite) with the following config: 1# (Main site) Home: http:// www.mysite.com Upload Path: wp-content/uploads Fileupload Url: http:// www.mysite.com/wp-content/uploads 2# Home: http:// www.mysite.com/en/ Upload Path: wp-content/blogs.dir/2/files Fileupload Url: http:// www.mysite.com/en/files My ...
After reading several topics about this issue I've found this: Issues with old WPMU installs If you installed WordPress MU in subfolder/subdirectory (not in root folder on your server > via ftp) and you have problem with image library, where thumbnails and images do not show, > you may need to manually add in rewrite r...
Broken image multisite
wordpress
I would allow guests comments who are not registered yet to comment only one single post. Other posts have to be commentable just for registered users.
That sounds like a useful feature. To get what you need you have to change three things: Add a checkbox to enable anonymous comments per post. Save the checkbox value together with the post. Filter the checks for the comment registration requirement on the post views to enable the comment form and on the actual comment...
Allow guests comments on single post
wordpress
I want to check if a user is logged in. If he is, I want to redirect him to page A, and if he isn’t to page B. The redirect should happen per JavaScript after a button has been clicked – so I need the status or the URL to be available in JavaScript. How can I get these data from WordPress into JavaScript?
To test if a user is logged in use <code> is_user_logged_in() </code> . To redirect a visitor use <code> wp_redirect($location, $status = 302) </code> . You can combine both: <code> &lt;?php $location = 'http://localhost'; if ( is_user_logged_in() ) $location = admin_url( '/' ); wp_redirect( $location ); </code> In Jav...
Redirect based on log-in status per JavaScript
wordpress
I have a search widget with a drop down populated with my custom taxonomies. I need one of the other input fields to only show when a certain taxonomy or its children are selected. Before you say this is only a jquary question, please bare with me. I think I need to edit wp_dropdown_categories() with Walker_CategoryDro...
My full working code for those interested <code> &lt;?php // Equipment Category Dropdown, thanks https://gist.github.com/2902509 class Walker_SlugValueCategoryDropdown extends Walker_CategoryDropdown { function start_el(&amp;$output, $category, $depth, $args) { $pad = str_repeat('&amp;nbsp;', $depth * 3); $cat_name = a...
Search box with field hidden till drop down selection is made
wordpress
I created an options page for my plugin where the user can specify image dimensions which will be saved for later use. So far the image dimensions are entered by the user in one input field like 200x200. To make it easier for the user I want to split that into two input fields with a x between them(one for x, one for y...
Name one field <code> gpp_image_sizes[width] </code> and the second <code> gpp_image_sizes[height] </code> . You will get an array in your save callback: <code> $_POST = array ( 'gpp_image_sizes' =&gt; array ( 'width' =&gt; 100, // some number 'height' =&gt; 100, // some number ) ) </code>
Plugin options page - save two related options as one entry
wordpress
How can I remove the tag base that WordPress creates by default in permalinks? Any reason why it would be there in the first place?
It's probably there to help visually and programmatically distinguish tag URLs from pages; I'm not sure, I'm not a core developer of WordPress. But http://wordpress.org/extend/plugins/wp-no-tag-base/ and http://wordpress.org/extend/plugins/wp-no-category-base/ work well and do not make permanent changes to files or GUI...
How to remove tag base from permalinks
wordpress
How can I get something like this to work? <code> // in a plugin / theme: // This imaginary function will make WordPress think that the // current request is a 404. // Ideally this function could be ran anywhere, but realistically it // will probably have to be before the template_redirect hook runs. generate_404_someh...
<code> function generate_404_somehow() { global $wp_query; $wp_query-&gt;is_404 = true; } add_action('wp','generate_404_somehow'); </code> Of course, that will send all of you page to the 404 template. I don't know what the conditions are that this should fire or not fire. Or to be more cautious (see comments) ... <cod...
How do I programmatically generate a 404?
wordpress
I'm using WooCommerce for my store, and I need to be able to extend the Coupon post type... I need to add a selectable attribute of <code> membership_term </code> ... How do you extend a CPT created by another plugin? Is there an official hook that I'm not seeing to be able to modify an existing CPT?
I am not sure exactly what you are trying to 'extend', or how you want to extend it, but you can alter posts types with <code> add_post_type_support </code> , <code> remove_post_type_support </code> , and a few other functions . You can add metaboxes to the post type with <code> add_meta_box </code> setting the <code> ...
Extending a CPT by Created by another plugin
wordpress
I can create my theme without splitting it into separate files. Why do theme developers split WordPress theme into a few single files like header.php sidebar.php and etc?
You need that for child themes. If you have a separate <code> header.php </code> a child theme can use its own <code> header.php </code> and override the parent theme’s file. Plus, <code> header.php </code> and <code> footer.php </code> are used in <code> wp-signup.php </code> . Another reason is readability: Putting a...
reason of splitting theme files to multiple files
wordpress