Skip to main content

Questions tagged [php]

For questions about the server-side programming language that the WordPress core, plugins and themes are written in. Questions about using PHP outside a WordPress context are off-topic but might be asked on Stack Overflow.

Filter by
Sorted by
Tagged with
66 votes
3 answers
135k views

Allow HTML in excerpt

Here is my excerpt code. // Generate custom excerpt length function wpbx_excerpt_length($length) { return 300; } add_filter('excerpt_length', 'wpbx_excerpt_length'); How do I allow html like <...
user32447's user avatar
  • 835
71 votes
7 answers
109k views

What is the correct way to use WordPress functions outside WordPress files?

I read about 2 methods for initializing WordPress function outside of WordPress files so We can use these functions on any page or website outside the WordPress blog. Which one of these 2 methods is ...
alhoseany's user avatar
  • 1,201
31 votes
5 answers
81k views

How to update custom fields using the wp_insert_post() function?

The WordPress function is used for submitting data programatically. Standard fields to submit to incude the content, excerpt, title, date and many more. What there is no documentation for is how to ...
Robin I Knight's user avatar
24 votes
2 answers
12k views

How can I use WordPress functions in my stylesheet?

I have my style.php file looking like this. <?php header('Content-Type: text/css');?> #div{ background:<?php echo get_option('bgcolor');?>; } This does not work, but when I do this ...
Ronny K's user avatar
  • 581
18 votes
7 answers
9k views

Inserting terms in an Hierarchical Taxonomy

I'm really having a few issues with inserting terms. Here is my scenario: I have a taxonomy called veda_release_type: //Release Type and Region $labels = array( 'name'=> _x('...
Manny Fleurmond's user avatar
137 votes
14 answers
601k views

How to get URL of current page displayed?

I want to add custom PHP code to ensure that whenever a page on my site loads in my browser, the URL of that page is echoed to the screen. I can use echo get_permalink(), but that does not work on ...
cag8f's user avatar
  • 1,967
65 votes
8 answers
88k views

How to get WordPress Time Zone setting?

Can someone tell me how to get the time zone that is set in the WordPress Admin? For example, if the blog is set to Eastern time, I need this exact string to print out: US/Eastern This is for a ...
user1462's user avatar
  • 1,294
6 votes
2 answers
21k views

Proper use of Output Buffer

I'm attempting to use actions to override function calls I currently have throughout a template (to make updating certain replicated sections easier). For example, in archives.php I have the following:...
Zach's user avatar
  • 1,933
5 votes
3 answers
5k views

Need help with friendly URL's in Wordpress

I'm creating som custom templates in Wordpress and I'm passing some data in the URL's. Currently my URL looks like this: http://www.mysite.com/designers/?id=43&name=designer+name The URL ...
Steven's user avatar
  • 2,610
17 votes
4 answers
31k views

How to manually fix the WordPress gallery code using PHP in functions.php?

It's been talked many times that Wordpress outputs some really bad code for the built-in gallery function. This is the core code responsible for the gallery output (in /wp-includes/media.php): ...
its_me's user avatar
  • 4,502
8 votes
1 answer
5k views

Allow Editors to edit pending posts but not draft ones

I have a large number of users with Editor Capabilities that help to go through the post submissions. This is my current setup for this role: As you can see, they are allowed to edit_posts and ...
Christine Cooper's user avatar
  • 8,828
38 votes
2 answers
88k views

what is correct way to hook when update post

i try to hook when post is updated but all hook i try never executed except updated_post_meta add_action('updated_post_meta', 'my_function'); function my_function($post_id) { echo 'This is ...
rusly's user avatar
  • 483
12 votes
4 answers
16k views

Disable Attachment Pages Completely

I would like to disable all attachment pages completely. I Googled it, but there's just information on how to redirect to parent post or homepage. That's not what I would call an elegant solution. Why ...
Maciej Kravchyk's user avatar
3 votes
3 answers
27k views

Display posts by month

I want to achieve something like this, I don't know if it is possible and what would be the best way to do it: The way I query the posts is like this: <div class="post"> <?php global $...
wpuser's user avatar
  • 195
2 votes
2 answers
576 views

Guidance with The Loop for CMS

Maybe I'm going about this the wrong way but this is my scenario... I would like to use WordPress as a CMS rather than a blogging platform. I have a website that will have somewhere between 25-50 ...
markmilly's user avatar
94 votes
11 answers
124k views

What are PHP extensions and libraries WP needs and/or uses?

Codex loosely only mentions PHP version in server requirements, however PHP can be configured in pretty wide range of excluding/including different parts. What are extensions/libraries that: are ...
Rarst's user avatar
  • 99.8k
48 votes
4 answers
272k views

How to set and use global variables? Or why not to use them at all

UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was <?...
JPollock's user avatar
  • 1,268
35 votes
3 answers
10k views

How exactly do automatic updates work?

I received an email this morning stating that my Wordpress site had been automatically updated to the latest version. I knew about the feature but I've always wondered exactly how it works. PHP isn't ...
DisgruntledGoat's user avatar
31 votes
6 answers
15k views

Running WP-Cron on Multisite networks the right way?

I have WordPress Multisite with several sites. I set up DISABLE_WP_CRON to true in my wp-config.php. If we set up cron task with wget or curl we have 30 sec rule to execute PHP script. It's so small ...
Kolya Korobochkin's user avatar
24 votes
5 answers
36k views

the_date() not working

I am using wordpress 3.2 and I did a query post like this: <?php query_posts("posts_per_page=1post=type&page=post_parent=10");?> Then I try to echo out the date of this post I queried like ...
zachdyer's user avatar
  • 343
6 votes
3 answers
9k views

Does an activated plugin automatically mean its methods are available to other WP functions?

I made a WordPress plugin like this: Class MY_CLASS { //codes } Global $myclass; $myclass = New MY_CLASS (); After installed and activated the plugin, can I use this class in other plugins without ...
Jenny's user avatar
  • 1,767
6 votes
3 answers
9k views

How to change the wp-login.php page title?

I've been using the document_title_parts hook to change the page title for some front end pages. However, this doesn't seem to work for the login, register and password management pages. How can I ...
henrywright's user avatar
  • 3,087
5 votes
1 answer
2k views

wp_delete_auto_drafts() deletes links in menus

Since yesterday the wp_scheduled_auto_draft_delete cron job somehow deletes all page entries from our menus. All entries in the table wp_postmeta with meta_key = '_menu_item_object' and meta_value = '...
Gellweiler's user avatar
4 votes
3 answers
14k views

How to export/import theme customizer settings?

I am wondering if it is possible to export theme customizer settings(theme_mods) to be imported into another install of the same theme. I know that the settings are saved into the database so I am ...
user1632018's user avatar
2 votes
1 answer
465 views

Stackoverflow type of badge plugin giving warnings in Wordpress 3.5

I modified an abandoned Stackoverflow form of badge plugin to work with Wordpress 3.4.2 and it does indeed. The full script for it is here: http://pastebin.com/Ta91zXiL When upgrading to Wordpress v3....
Christine Cooper's user avatar
  • 8,828
0 votes
1 answer
3k views

How to Use the Function is_user_logged_in To Display Different Menus?

So, I want to create different menus for people who are logged in or not. I got a reply that i should use a function if (is_user_logged_in()) { wp_name_menu(array('theme_location' => '...
Gediminas's user avatar
51 votes
7 answers
156k views

how to get page id of a page using page slug

I'm pretty new to WordPress and I was wondering if I could get a page id with its slug. Is it possible please let me know?
freaky's user avatar
  • 613
40 votes
1 answer
107k views

How to add product in woocommerce with php code [closed]

I want to add products with PHP code like below: $post_information = array( 'post_title' => 'new item shop', 'post_content' => 'this is new item shop', 'post_type' => 'post', '...
Hossein Hashemi's user avatar
30 votes
1 answer
38k views

How to create custom 401, 403 and 500 error pages?

When a 404 error is encountered, a 404.php template file can be used to render a custom error message. This is documented in the Template Hierarchy article. My aim is to create custom error pages ...
henrywright's user avatar
  • 3,087
28 votes
5 answers
3k views

Why have <?php and ?> on every line

I've seen this convention pretty much everywhere, and, at times, it comes close to driving me nuts: <?php //The loop ?> <?php while ( have_posts() ) : the_post(); ?> <?php ...
Indigenuity's user avatar
24 votes
2 answers
58k views

Query multiple custom post types in single loop

I'm aware there are several other posts that cover similar ground to what I'm about to ask. I have three custom post types running, in addition to 'posts'. I want to run a loop that pulls all posts ...
dannyw24's user avatar
  • 451
20 votes
1 answer
31k views

Setting $_SERVER['HTTPS']='on' prevents access to wp-admin

First off my server is sitting behind a load balancer. My SSL certificate sits on the load balancer and handles HTTPS. The data coming in on port 443 is forwarded to the Wordpress server using HTTP ...
nu everest's user avatar
17 votes
4 answers
16k views

User registration followed by automatic login

I am using a plugin modified for my purposes. What I am after is after the user has registered for it to automatically log them in and return them to the current page. At the moment it sends them an ...
Robin I Knight's user avatar
15 votes
5 answers
61k views

Setting custom cookies in Wordpress

I am trying to set cookies to re-route returning users to my a specific page within my Wordpress site. I'd like some advice with these 2 things: Where in the Wordpress php files should cookies be ...
Atticus's user avatar
  • 381
14 votes
2 answers
10k views

add_action in namespace not working

I decided to namespace my plugin, and I got it all to work, except in my main plugin file. I added two actions in that plugin, before calling the init method of the plugin. <?php namespace ...
dingo_d's user avatar
  • 1,920
12 votes
5 answers
32k views

How can I remove the "Add New" button in my custom post type?

I have many custom post types that need the Add [custom post type] feature but I have a custom post type of "About" and I do not need to "Add New" about to the about custom post type. So I want to ...
Lucas Santos's user avatar
12 votes
8 answers
4k views

Is there a way to use the Wordpress users but without loading the entire Wordpress core?

I have a Wordpress site and a web application that can be used only by the registered (Wordpress) users. Now I'm loading wp-blog-header.php to check if the user is logged in. Everything is working ...
Victor's user avatar
  • 263
8 votes
3 answers
7k views

start_lvl Ignored in Custom walker_nav_menu

This is my first project involving WordPress and I've got stuck trying to create a custom walker for a footer menu. I basically want to change the menu from the <ul> <li></li> </...
fenfe1's user avatar
  • 81
8 votes
1 answer
6k views

How can I fetch loop of post titles via AJAX?

I have a list of the most recent post titles in sidebar.php. Here is an example of how that code looks: <?php $args = array('posts_per_page' => 20); ?> <?php $sidebar = new WP_Query($args)...
Sahas Katta's user avatar
7 votes
3 answers
44k views

How WordPress encrypt password? [duplicate]

Possible Duplicate: How to validate WordPress generated password in DB using PHP? I am working with site that is done with WordPress, and I need to add some parts that are outside WP, and to ...
user avatar
6 votes
2 answers
9k views

Preserve custom URL parameter on more pages

I created a custom URL parameter for sorting posts by their vote scores. I have a "most voted" link that sends a ?sort=most_voted URL paramater and using a query posts filter I display posts with most ...
wpStudent's user avatar
  • 141
5 votes
1 answer
5k views

How to make simply "report" button on posts

I'm building up a video-site using wordpress. It embeds videos from different sites. I really need a simply "Report broken video"-button that saves the url in a database or emails it to me. I've ...
Torben's user avatar
  • 57
4 votes
2 answers
11k views

Is it possible to disable a function of a parent theme?

I was wondering whether it is possible to completely disable a function that is called in a parent theme's functions.php and if so, how? (Of course without deleting the function. Rather by adding ...
Bram Vanroy's user avatar
4 votes
2 answers
853 views

Static Frontpage Pagination - Custom loop

I created a custom content template, assigned it to a page and coded the query. Everything appears to be working as they should. The only issue I have is with the pagination. So, when I go the second ...
Konstantinos Koletsas's user avatar
4 votes
4 answers
19k views

How to validate WordPress generated password in DB using PHP?

I am working with site that is done with WordPress, and I need to add some parts that are outside WP, and to check user login, Logging users outside WP. I tried with md5 of password but it's not... ...
SharkTheDark's user avatar
4 votes
1 answer
3k views

Metabox repeating fields - radio buttons not saving correctly

I have multiple radio buttons set up inside of a metabox in a custom post type. I have created the metabox like so: add_action('admin_init', 'add_meta_boxes', 1); function add_meta_boxes() { ...
EHerman's user avatar
  • 999
3 votes
2 answers
24k views

Create Image Uploader for Widget

I found this post// Use Media upload in custom widget on wordpress 3.5 I'm not experienced in any of this so I pretty much just copied the code he provided into my own functions.php file. I uploaded ...
keilowe's user avatar
  • 90
3 votes
2 answers
4k views

Admin Bar (Toolbar) not showing on custom PHP file that loads WordPress

I've made my own PHP page and used it as a part of my WordPress website. I'm using some WordPress functions and want to have it fully integrated with WordPress itself. Although I've loaded WordPress,...
jmeinlschmidt's user avatar
2 votes
3 answers
6k views

Counting number of posts in a category and its sub categories and displaying result using shortcode

I am trying to create a shortcode to display the posts count in a category. I have successfully done this using this code: // Add Shortcode to show posts count inside a category function ...
Atef Wagih's user avatar
1 vote
1 answer
3k views

Archive listing of posts by publish year (multiple years)

I have an archive page showing all blog posts (in a specific category). With a growing number of posts, I want to separate these by publish year. For example (simplified), I'd like the following: ...
t-jam's user avatar
  • 183

1
2 3 4 5
12