Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
27 votes
4 answers
36k views

Manually set global $post vars with an ID, in order to use template tags

I have a function retrieving ID's of posts by very specific means. I need to be able to set the global $post in order to use functions like the_content(), which does not allow an ID as a parameter. ...
Mild Fuzz's user avatar
  • 4,190
11 votes
1 answer
16k views

What is This esc_html_e() i wordpress php?

why do developers use <?php esc_html_e() >? in 404 pages, what does it mean, how does it works?
TheDose's user avatar
  • 198
4 votes
1 answer
4k views

Show modified time if post is actually modified

I want to display post updated time only if post is modified, I am using function the_modified_time() . So I just read about that there is if statement that can be used to check if post is even ...
Usce's user avatar
  • 467
4 votes
1 answer
24k views

Define Function in functions.php or plugin and call in theme loop

I need to define a function in functions.php or a plugin and be able to call it inside the theme's loop & outside. Example; I have a $product_price = get_post_meta(get_the_ID(), 'product-price', ...
Raphaello's user avatar
4 votes
2 answers
1k views

Build a content and excerpt grid loop with paging and options for # of posts

What I'd like to do: on index.php, a loop that shows a selectable number of full posts using the_content and then below that shows a selectable number (the number of posts can be hardcoded in the ...
markratledge's user avatar
  • 8,735
4 votes
1 answer
5k views

AJAX handler throws 400 (Bad request) - why?

I am trying to apply a "Load more posts" function to a post loop, but I am dealing with a 400 Bad request, when admin-ajax.php is referred to. The reference I used is this - https://rudrastyh.com/...
Dougless's user avatar
3 votes
2 answers
5k views

How to display the_post_thumbnail if a post has one or otherwise display the first image in a post?

I would like to create a condition that checks to see if a post has a thumbail and if it does display it, otherwise display the first image in a post. I tried something like this in my loop.php but ...
Matt's user avatar
  • 1,131
3 votes
1 answer
1k views

Displaying post per day

Currently I have the code displayed below. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12"> <a class="...
Ritzy's user avatar
  • 141
2 votes
3 answers
31k views

How to Display Post View Count

I am trying to display post view counts. I've tried below function to display the post view count, but I'm getting same post view for all the post in loop. Not getting correct post view count. ...
Jack Torris's user avatar
2 votes
1 answer
5k views

Adding WooCommerce to a Custom Theme - not working [closed]

I have a custom Wordpress theme I'm doing for a client and I need to make it woo-commerce compatible. I've followed the steps on the woocommerce docs which are: 1) create a woocommerce.php file 2)...
pjk_ok's user avatar
  • 908
2 votes
1 answer
81 views

A snippet after every image

folks. I need to put a piece of code after every post image (post attached image). it's something like this: <img class="alignnone size-full wp-image-3079" src="imgurl.jpg" alt="02" width="2592" ...
Daniel Costa's user avatar
2 votes
1 answer
946 views

Function to show only first instance of shortcode

I need to add a function to my theme to remove additional instances of a shortcode in a post. First off I wonder if i'm approaching this wrong, but I have a theme that is drastically reformats the ...
HjalmarCarlson's user avatar
2 votes
1 answer
276 views

How do you output custom code between posts in the loop?

I am trying to put a header before past posts and after future posts. I'm using get_posts() in a function to output the posts using a foreach loop for a custom post type ordered by date (meta key). If ...
Confused One's user avatar
2 votes
2 answers
2k views

Automatically insert php function into post $the_content

I am trying to have 2 php functions automatically inserted in every post for my CPT. The problem I am having is that even though I've found a way to add text, Im not sure how to add the php functions ...
730wavy's user avatar
  • 193
2 votes
1 answer
777 views

Creating loop within functions.php

I'm using Woocommerce on my website, on the checkout page I've got a custom select checkout field with radio buttons. I'm using this working snippet within my functions.php: /** * Add the field to ...
WPNiko's user avatar
  • 31
2 votes
0 answers
6k views

Display WooCommerce subscriptions for user [closed]

I'm trying to display a user's Subscriptions within their WooCommerce dashboard. I am able to do this, but I also want to add some additional fields related to the Subscription (title, next renewal ...
Garconis's user avatar
  • 144
2 votes
0 answers
1k views

How to use max and min values of custom fields

How to use max and min values of custom fields (created via ACF, repeater type)? For axample, I've custom post type 'auto' and there are a lot of models. Each post(model) has few values of price (...
Влад's user avatar
1 vote
1 answer
851 views

Custom Shortcode, functions PHP WP_Query loop

I have the following code in my functions.php file:- function featured_properties_func( $atts ) { $args = array( 'posts_per_page'=> -1, 'post_type' => 'properties', ...
nsilva's user avatar
  • 227
1 vote
2 answers
2k views

Most elegant way to enqueue scripts in function.php with foreach loop

I wonder is there a way of running wp_register_script and enqueue with the help of foreach loop to manage label and dir? For example, function wbs_app_components(){ $scripts_list=array( ...
Ezeewei's user avatar
  • 185
1 vote
2 answers
7k views

Filtering posts by category name based on page's slug

I've created a page template and the goal is to create a loop that gets all posts by category name. The category name is passed from the slug of the page name. I haven't been able to get this to work ...
NW Tech's user avatar
  • 707
1 vote
2 answers
38k views

How would I create a shortcode to display a custom post within a page or regular post?

I would like to create a shortcode that will extract information for a custom post, and display it within a Page or regular Post. Specific use case: I have a custom post type "Film" for a film ...
gillespieza's user avatar
  • 1,285
1 vote
2 answers
62 views

2 Loops, Only Displaying 1 Loop in Both Loops

I have 2 loops, movie trailers and gaming trailers but gaming trailers is displaying under both Movie Trailers and Gaming Trailer. Each loop displays the post tagged with either Movie Trailer or ...
Joe Bobby's user avatar
  • 749
1 vote
2 answers
370 views

How to speed up a wordpress function with multiple loops?

I am a PHP novice and wrote this function. It is an alphabetical navigation which shows only the letter that have posts in both that letter and the currently filtered "genero" taxonomy term. I use ...
HandiworkNYC.com's user avatar
1 vote
1 answer
931 views

Custom excerpt function re-factoring

This may be more of a php best practices question, but here goes... I am using a custom excerpt trim function: function new_wp_trim_excerpt($text) { // Fakes an excerpt if needed global $post; ...
two7s_clash's user avatar
1 vote
1 answer
8k views

How to get current post category details inside "loop"?

I have a rather simple problem I can't solve. I have custom styling for my cards and one of the elements of the cards is the category, when I access the_category() from the Loop it comes with its own ...
Mark20's user avatar
  • 17
1 vote
1 answer
217 views

Multiple Loops Inside a Function

What I understand from the CODEX, (https://codex.wordpress.org/Class_Reference/WP_Query#Multiple_Loops). then I'm trying to do a list of posts like this: <nav id="cbp-hrmenu" class="cbp-hrmenu ...
Locke's user avatar
  • 185
1 vote
2 answers
2k views

Best way to style first post differently?

I am building a custom (child) theme and I want to style the first post of my loop in a different way than the others (bigger image, different position of some stuff). Which is the best way of doing ...
Cmorales's user avatar
  • 143
1 vote
1 answer
158 views

Help with Wordpress Query

I'm sort of a noob when it comes to Wordpess; I've only recently started building themes and I've run into a wall. I'm trying to feature 3 different articles at the top of my site using wpquery and ...
Matt's user avatar
  • 11
1 vote
1 answer
892 views

How do I pull excerpts from pages?

So I enabled custom excerpts on my pages with this function. add_action('init', 'page_excerpts'); function page_excerpts() { add_post_type_support( 'page', 'excerpt' ); } However, When I enter ...
Zach Shallbetter's user avatar
1 vote
1 answer
778 views

Get first URL from post content

Basically all I want to do is if the post format is "link" rather than link to the post from the blog index, link to the link pasted within the post content. In my index.php I have: <h3> <...
caffeinehigh's user avatar
1 vote
2 answers
5k views

Problem with calling custom function in a foreach loop

I have a custom function in functions.php that excludes specific category from the category list: function incomplete_cat_list() { $first_time = 1; foreach((get_the_category()) as $...
Anda's user avatar
  • 57
1 vote
1 answer
56 views

Converting a dynamic piece of code using WordPress Loop into a static one using Post ID

<?php if (is_single()) { ?> <?php $imvi = get_post_meta(get_the_ID(), 't_puck_imvi', true); ?> <div class="class1" <?php if( 'none' === $imvi) { ?> style="display:none;" <?...
WordCent's user avatar
  • 1,877
1 vote
2 answers
3k views

Having a Function Inside of the Loop

I am trying to make a frontend product editor for WooCommerce, and have a loop that returns all of the products for the current user. I am trying to use gravity forms as the editor, so a single ...
Kyle's user avatar
  • 270
1 vote
1 answer
379 views

Show css depending on activity type in BuddyPress activity-loop [closed]

I was wondering if anyone knew of a way to show specific styles to the activity loop depending on the activity type? This is what I had an idea of: function mycustom_act_type() { if ('...
Sin's user avatar
  • 55
1 vote
0 answers
70 views

Getting different functions data while using while loop in wordpress

I have added this code in the function.php file but when I use while loop in any other files this function is getting triggered. <?php add_action('loop_start', 'userlogin'); function userlogin() { ...
Nabeen's user avatar
  • 11
1 vote
1 answer
50 views

Exclude category from

I am trying to exclude a category from <?php the_category(', ') ?> inside my loop. I came across the following code on CSS tricks that says would solve the problem. You add this to the functions:...
Ed Manson's user avatar
1 vote
0 answers
329 views

Create a new query in function.php to filter blog posts

My goal is to filter blog posts (those which are requested in the blog page - Reading settings) depending on an expiration date, and then to change their category depending on a choosen future ...
Sioban's user avatar
  • 11
1 vote
1 answer
449 views

get author_name from queried post

All I'm trying to do is, get the author name of the current post and set it's name as a tag. I tried changing author_id to author_name but didn't really get anything back. wp_set_post_tags should ...
J patel's user avatar
  • 15
1 vote
0 answers
41 views

Blog posts repeat

Good Afternoon! I have having an issue on a site I am working on where in that the blog posts "repeat" and by that I mean they are being displayed twice. Ideally I would like the page to work as ...
NeoLobster's user avatar
1 vote
1 answer
858 views

Limit length of first excerpt in the loop

Searched everywhere but have not seem this come up. I'm looking to set the length of the excerpts in the loop in functions.php but I need the first post only to have double the characters as the rest. ...
JPB's user avatar
  • 145
1 vote
0 answers
292 views

how to refresh div on template part?

i'm keep learning about wordpress development and i've developed this template-part and loop and i need that entire div#dreams-gallery refresh after a period of time, let's say 10 seconds. Here's my ...
Vasco Antunes's user avatar
1 vote
0 answers
143 views

Shortcode not working with post counter

I am trying to make this a Wordpress shortcode, i mean the below code, but it doesn't seem to work , I included this in my function.php file, but it gave back multiple query result, as seen in the ...
Kazem Nocktrine's user avatar
1 vote
0 answers
342 views

Can't find infinite loop cause

I am working on the below function which will eventually create a set of posts based on meta data entered into a "parent" post. I'm running into an infinite loop when hitting the save button, which I ...
Eckstein's user avatar
  • 1,119
1 vote
1 answer
112 views

Checking array against author id in loop

So I have a function in Wordpress with a plugin that returns a list of friends as an array. The function code is here: function friends_get_list($tmp_uid, $friend_status=1) { global $wpdb; $...
dwinnbrown's user avatar
1 vote
0 answers
96 views

Default Custom Field Value Automatically Update

I have created a hidden custom field with a php function as its value. Like so -- $value_rating = get_post_meta($Property_Id, 'vr', true); <input type="hidden" name="vr" class="form-control ...
730wavy's user avatar
  • 193
1 vote
0 answers
54 views

Multiple Loops Meta Data

I am now trying to figure out how to create the functions/ loops to pull my data from custom post types. I have two post types(keys): And I need to pull the data from both to run my functions. ...
Jon C's user avatar
  • 73
0 votes
2 answers
2k views

Why doesn't is_page(id) work in functions.php?

When is code in functions.php executed? Is it during the loop? The following does not work when placed in functions.php (not within a function) : if (is_page( 27 )) { echo 'this is the apply page'; ...
codecowboy's user avatar
  • 1,778
0 votes
2 answers
960 views

The Loop not looping?

After much troubleshooting and searching, I think I finally understand how to get The Loop going. Except I can't seem to get it to actually loop! I have created a Child theme, and added a functions....
BruceWayne's user avatar
0 votes
1 answer
25 views

Change all author links in Blog roll

I want all the author links on my blog page to go to a specific url ("/about") instead of the individual author pages. I know this can be done easily with JavaScript, but is there way to do it in ...
AJT's user avatar
  • 187
0 votes
1 answer
85 views

Custom Pagination is Broken

Good Afternoon! I am working on adding pagination to a website and currently it is working fine but for some reason the function loads an extra page. We have 7 posts, and I set it to display 4 posts ...
NeoLobster's user avatar